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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider">
   <?php if(get_theme_mod('kids_online_store_slider_setting',true) != ''){ ?>
    <?php $kids_online_store_slide_pages = array();
      for ( $kids_online_store_count = 1; $kids_online_store_count <= 3; $kids_online_store_count++ ) {
        $kids_online_store_mod = intval( get_theme_mod( 'kids_online_store_top_slider_page' . $kids_online_store_count ));
        if ( 'page-none-selected' != $kids_online_store_mod ) {
          $kids_online_store_slide_pages[] = $kids_online_store_mod;
        }
      }
      if( !empty($kids_online_store_slide_pages) ) :
        $kids_online_store_args = array(
          'post_type' => 'page',
          'post__in' => $kids_online_store_slide_pages,
          'orderby' => 'post__in'
        );
        $kids_online_store_query = new WP_Query( $kids_online_store_args );
        if ( $kids_online_store_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $kids_online_store_query->have_posts() ) : $kids_online_store_query->the_post(); ?>
        <div class="slider-box">
          <?php if(has_post_thumbnail()){
            the_post_thumbnail();
            } else{?>
            <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/img/slider.png" alt="" />
          <?php } ?>
          <div class="slider-inner-box">
            <?php if(get_theme_mod('kids_online_store_slider_title_setting',1) == 1){ ?>
              <h2><?php the_title(); ?></h2>
            <?php }?>
            <?php if(get_theme_mod('kids_online_store_slider_content_setting',1) == 1){ ?>
              <p class="mb-5"><?php $kids_online_store_excerpt = get_the_excerpt(); echo esc_html( kids_online_store_string_limit_words( $kids_online_store_excerpt, esc_attr(get_theme_mod('kids_online_store_slider_excerpt_length', 15)) ) ); ?></p>
            <?php }?>
            <?php if(get_theme_mod('kids_online_store_slider_button_setting',1) == 1 && get_theme_mod('kids_online_store_slider_button_text','SHOP NOW') != ''){ ?>
              <div class="slide-btn"><a href="<?php the_permalink(); ?>"><?php esc_html_e(get_theme_mod('kids_online_store_slider_button_text','SHOP NOW')); ?></a></div>
            <?php }?>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
    <?php } ?>
  </section>

 <?php if(get_theme_mod('kids_online_store_product_setting',true) != ''){ ?>
  <section id="homepage-product">
    <div class="container">
      <div class="row product-home-box">
        <?php
        if ( class_exists( 'WooCommerce' ) ) {
          $kids_online_store_args = array(
          'post_type' => 'product',
          'posts_per_page' => get_theme_mod('kids_online_store_home_product_number'),
          'product_cat' => get_theme_mod('kids_online_store_home_product'),
          'order' => 'ASC'
          );
          $loop = new WP_Query( $kids_online_store_args );
          while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <div class="col-lg-3 col-md-4 col-sm-6">
              <div class="product-box">
                <div class="product-image">
                  <span class="product-sale-tag">
                    <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
                  </span>
                  <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.esc_url(woocommerce_placeholder_img_src()).'" />'; ?>
                </div>
                <h4><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>">
                  <?php the_title(); ?><span class="screen-reader-text"><?php echo esc_html('best-seller-content', 'kids-online-store' ) ; ?></span>
                </a></h4>
                <p class="price"><?php echo $product->get_price_html(); ?></p>
              </div>
            </div>
          <?php endwhile; wp_reset_query(); ?>
        <?php } ?>
      </div>
    </div>
  </section>
<?php } ?>

  <section id="content-section" class="container">
    <?php
      if ( have_posts() ) :
        while ( have_posts() ) : the_post();
            the_content();
        endwhile;
      endif;
    ?>
  </section>
</main>

<?php get_footer(); ?>
