<?php
/**
 * Template Name: Home
 */

get_header();
?>

<!-- start body -->
<div class="bdy">



    <section class="about-wrap">
        <div class="container">
            <div class="row">
                <div class="col-md-10 col-md-offset-1 col-sm-8 col-sm-offset-2 text-center">
                    <?php the_field('about_us'); ?>
                </div>
            </div>
        </div>
    </section>

    <section class="product-wrap">
        <div class="container">
            <div class="row">
                <div class="col-md-12 text-center">
                    <h2 class="hd2">OUR PRODUCTS</h2>
                    <div class="spacer gap-20"></div>
                    <div class="common-tab-style">
                    <div id="horizontalTab">
                        <ul class="resp-tabs-list">
                        <?php 
                            $product_categorys = get_terms(array( 
                            'taxonomy' => 'product_cat',
                            'parent'   => 0,
                            'order' => 'DESC'
                            ) );
                             foreach ($product_categorys as $pro_category) { 
                                if(!($pro_category->term_id==16)){
                            ?>
                            <li><?php echo $pro_category->name;?></li>
                            <?php  } } ?>
                        </ul>
                        <div class="resp-tabs-container">
    <?php $a=1;  foreach ($product_categorys as $recloop) {  ?>

                        <div>
                            <div id="product<?php echo $a; ?>" class="owl-carousel theme-heading">  

<?php   
      $recent_products = array( 'post_type' => 'product', 'order' => 'DESC','posts_per_page'   => -1,'orderby'         => 'id',
      'tax_query' => array(
    array(
      'taxonomy' => 'product_cat',
      'field'    => 'term_id',
      'terms'    => $recloop->term_id,
    ),
  ), 

      );
      $recent_prod =  new WP_Query( $recent_products );
      if ( $recent_prod->have_posts() ) {
      while($recent_prod->have_posts() ) { $recent_prod->the_post();
        $shop = wc_get_product();
 ?>
                                <div class="item">
                                    <div class="produt-bx">
                                        <figure>
                                        	<?php if ( has_post_thumbnail() ) { ?>
                                              <img src="<?php the_post_thumbnail_url(); ?>" alt="" class="img-responsive">
                                        	<?php } else{ ?>
                                              <img src="http://via.placeholder.com/360x340" alt="" class="img-responsive">
                                        	<?php } ?>
                                        </figure>
                                        <h3><?php the_title(); ?></h3>
                                        <a class="blue-btn" href="<?php echo esc_url(get_permalink());?>">ORDER NOW</a>
                                    </div>
                                </div>
    <?php  } } ?>

                            </div>
                        </div>
<?php $a++;  } ?>
                        </div>
                    </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="best-selling-wrap">
        <div class="container">
            <div class="row">
                <div class="col-md-12 text-center">
                    <h2 class="hd2">RECENTLY ADDED EQUIPMENTS</h2>
                    <div class="spacer gap-20"></div>
                    <div id="product4" class="owl-carousel theme-heading">  
    <?php   
      $product = array( 'post_type' => 'product', 'order' => 'ASC','posts_per_page'   => -1,'meta_key'        => 'total_sales','orderby' => 'meta_value_num',);
      $r_products =  new WP_Query( $product );
      if ( $r_products->have_posts() ) {
      while($r_products->have_posts() ) { $r_products->the_post();
        $shop = wc_get_product();
    ?> 
                        <div class="item">
                            <div class="produt-bx">
                                <figure>
                                    <?php if ( has_post_thumbnail() ) { ?>
                                        <img src="<?php the_post_thumbnail_url(); ?>" alt="" class="img-responsive">
                                    <?php } else{ ?>
                                        <img src="http://via.placeholder.com/360x340" alt="" class="img-responsive">
                                    <?php } ?>
                                </figure>
                                <h3><?php the_title(); ?></h3>
                                <a class="blue-btn" href="<?php echo esc_url(get_permalink());?>">ORDER NOW</a>
                            </div>
                        </div>
    <?php } } ?>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="blog-wrap">
        <div class="container">
            <div class="row">
                <div class="col-md-12 text-center">
                    <h2 class="hd2">RECENT BLOGS</h2>
                    <div class="spacer gap-20"></div>
                </div>
    <?php 
            $posts = array( 'post_type' => 'post', 'order_by' => 'id', 'order' => 'ASC', 'posts_per_page'   => 1 );      
            $blog = new WP_Query($posts);
            if ( $blog->have_posts() ) {
              while($blog->have_posts()) {  $blog->the_post();
        ?>
    <div>
                <div class="col-sm-6">
                    <div class="blog-content">
                        <h3><?php the_title(); ?></h3>
                        <p class="post-date"><?php echo date('j M, Y') ?></p>
                        <p class="para2"><?php echo wp_trim_words(get_the_content(),'30','...'); ?></p>
                        <a class="red-btn" href="<?php echo esc_url(get_permalink());?>">Read More</a>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="blog-img">
                        <figure class="big-image"><?php if(has_post_thumbnail()) {?>
                        <img class="img-responsive" src="<?php echo the_post_thumbnail_url(); ?>" >
                      <?php } else { ?>
                        <img class="img-responsive" src="<?php echo IMAGE_PATH; ?>images/noImg.jpg">
                      <?php } ?></figure>
                        
                    </div>
                </div>
        </div>
    <?php } } ?>
            </div>
        </div>
    </section>


</div>
<!-- end body -->

<?php
get_footer();
