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

get_header(); ?>

<main id="skip-content">
  <section id="top-slider">
    <div class="container">
      <?php if(get_theme_mod('fashion_blogs_slide_setting','1')){ ?>
      <?php $fashion_blogs_slide_pages = array();
        for ( $fashion_blog_count = 1; $fashion_blog_count <= 3; $fashion_blog_count++ ) {
          $fashion_blog_mod = intval( get_theme_mod( 'fashion_blogs_top_slider_page' . $fashion_blog_count ));
          if ( 'page-none-selected' != $fashion_blog_mod ) {
            $fashion_blogs_slide_pages[] = $fashion_blog_mod;
          }
        }
        if( !empty($fashion_blogs_slide_pages) ) :
          $fashion_blog_args = array(
            'post_type' => 'page',
            'post__in' => $fashion_blogs_slide_pages,
            'orderby' => 'post__in'
          );
          $fashion_blog_query = new WP_Query( $fashion_blog_args );
          if ( $fashion_blog_query->have_posts() ) :
            $i = 1;
      ?>
      <div class="owl-carousel" role="listbox">
        <?php  while ( $fashion_blog_query->have_posts() ) : $fashion_blog_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('fashion_blogs_slider_title_setting',1) == 1){ ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php }?>
              <?php if(get_theme_mod('fashion_blogs_slider_content_setting',1) == 1){ ?>
                <div class="meta-info-box mb-2">
                  <span class="entry-author"><?php esc_html_e('BY','fashion-blogs'); ?> <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' )) ); ?>"><?php the_author(); ?></a></span>
                  <span class="ms-2"></i><?php echo esc_html(get_the_date()); ?></span>
                </div>
              <?php }?>
              <?php if(get_theme_mod('fashion_blogs_slider_button_setting',1) == 1 && get_theme_mod('fashion_blogs_slider_button_text','Read More') != ''){ ?>
                <div class="slider-box-btn mt-4">
                  <a href="<?php the_permalink(); ?>"><?php esc_html_e(get_theme_mod('fashion_blogs_slider_button_text','Read More')); ?></a>
                </div>
              <?php }?>
            </div>
          </div>
        <?php $i++; endwhile;
        wp_reset_postdata();?>
      </div>
      <?php else : ?>
        <div class="no-postfound"></div>
      <?php endif;
      endif;?>
      <?php }?>
    </div>
  </section>

<?php if(get_theme_mod('fashion_blogs_latest_post_setting','1')){ ?>
  <section id="latest_post" class="py-5">
    <div class="container">
      <?php if(get_theme_mod('fashion_blogs_latest_post_title') != ''){ ?>
        <h2><?php echo esc_html(get_theme_mod('fashion_blogs_latest_post_title')); ?><i class="fas fa-caret-right ms-2"></i></h2>
      <?php }?>
      <div class="row mt-4">
        <?php $fashion_blogs_other_latest_post_section = array();
          $latest_post_loop = get_theme_mod('fashion_blogs_latest_post_loop');
          for ($i=1; $i <= $latest_post_loop; $i++) {
            $fashion_blog_mod = intval( get_theme_mod( 'fashion_blogs_other_latest_post_section' .$i));
            if ( 'page-none-selected' != $fashion_blog_mod ) {
              $fashion_blogs_other_latest_post_section[] = $fashion_blog_mod;
            }
          }
          if( !empty($fashion_blogs_other_latest_post_section) ) :
          $fashion_blog_args = array(
            'post_type' => 'post',
            'post__in' => $fashion_blogs_other_latest_post_section,
            'orderby' => 'post__in'
          );
          $fashion_blog_query = new WP_Query( $fashion_blog_args );
          if ( $fashion_blog_query->have_posts() ) :
            $i = 1;
        ?>
        <?php while ( $fashion_blog_query->have_posts() ) : $fashion_blog_query->the_post(); ?>
          <div class="col-lg-3 col-md-6 col-sm-6">
            <div class="article-box">
              <?php if ( has_post_thumbnail() ) { ?><?php fashion_blogs_post_thumbnail(); ?><?php }?>
              <div class="entry-summary p-3 m-0">
                <a href="<?php the_permalink(); ?>" class="mb-2 d-block text-uppercase postcat-name"><?php $caty = get_the_category(); echo esc_html( $caty[0]->cat_name); ?></a>
                <?php the_title('<h3 class="entry-title pb-3"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>');?>
                <div class="meta-info-box mb-2">
                  <span class="entry-author"><?php esc_html_e('BY','fashion-blogs'); ?> <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' )) ); ?>"><?php the_author(); ?></a></span>
                  <span class="ms-2"></i><?php echo esc_html(get_the_date()); ?></span>
                </div>
                <a href="<?php the_permalink(); ?>" class="btn-text"><?php esc_html_e('Read More','fashion-blogs'); ?></a>
              </div>
            </div>
          </div>
        <?php $i++; endwhile;
        wp_reset_postdata();?>
        <?php else : ?>
          <div class="no-postfound"></div>
        <?php endif;
        endif;?>
      </div>
    </div>
  </section>
<?php }?>

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

<?php get_footer(); ?>
