<?php
/**
 * Template Name: Custom home
 */

get_header(); ?>

<?php 
  $archive_year  = get_the_time('Y'); 
  $archive_month = get_the_time('m'); 
  $archive_day   = get_the_time('d'); 
?>

<main id="maincontent" role="main">
  <?php do_action( 'perfect_blog_before_slider' ); ?>
  <?php /** slider section **/ ?>
  <?php if( get_theme_mod('perfect_blog_slider_hide_show',true) != '' || get_theme_mod('perfect_blog_responsive_slider', true) != ''){ ?>
    <section id="slider">
      <div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel" data-interval="<?php echo esc_attr(get_theme_mod('perfect_blog_slider_speed_option', 3000)); ?>"> 
        <?php $perfect_blog_slider_page = array();
          for ( $count = 1; $count <= 4; $count++ ) {
            $mod = intval( get_theme_mod( 'perfect_blog_slidersettings_page' . $count ));
            if ( 'page-none-selected' != $mod ) {
              $perfect_blog_slider_page[] = $mod;
            }
          }
          if( !empty($perfect_blog_slider_page) ) :
          $args = array(
              'post_type' => 'page',
              'post__in' => $perfect_blog_slider_page,
              'orderby' => 'post__in'
          );
          $query = new WP_Query( $args );
          if ( $query->have_posts() ) :
            $i = 1;
        ?>     
        <div class="carousel-inner" role="listbox">
          <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
          <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
            <?php if(has_post_thumbnail()){
                  the_post_thumbnail();
              } else{?>
              <img src="<?php echo esc_url(get_theme_file_uri()); ?>/theme-block-pattern/images/banner.png" alt="" />
            <?php } ?>
            <div class="carousel-caption wow zoomIn">
              <div class="inner_carousel">
                <?php if( get_theme_mod('perfect_blog_slider_title_Show_hide',true) != ''){ ?>
                    <h1><a href="<?php echo esc_url( get_permalink() );?>"><?php the_title();?><span class="screen-reader-text"><?php the_title(); ?></span></a></h1> 
                <?php } ?>
                <?php if( get_theme_mod('perfect_blog_slider_content_Show_hide',true) != ''){ ?>
                  <p><?php $perfect_blogging_excerpt = get_the_excerpt(); echo esc_html( perfect_blog_string_limit_words( $perfect_blogging_excerpt, esc_attr(get_theme_mod('perfect_blog_slider_excerpt_length','30')))); ?></p> 
                <?php } ?>
                <?php if( get_theme_mod('perfect_blog_slider_button','Read More') != '' || get_theme_mod('perfect_blog_slider_button_url') != ''){ ?>
                  <div class="more-btn">              
                    <a href="<?php echo esc_url(get_theme_mod('perfect_blog_slider_button_url')!= '') ? esc_url(get_theme_mod('perfect_blog_slider_button_url')) : esc_url(get_permalink()); ?>" class="p-0 text-uppercase"><?php echo esc_html(get_theme_mod('perfect_blog_slider_button','Read More'));?><span class="more"><i class="fas fa-long-arrow-alt-right ms-2"></i></span><span class="screen-reader-text"><?php echo esc_html(get_theme_mod('perfect_blog_slider_button','Read More'));?><span class="more"><i class="fas fa-long-arrow-alt-right"></i></span></span></a>
                  </div>   
                <?php } ?>           
              </div>
            </div>
          </div>
          <?php $i++; endwhile; 
          wp_reset_postdata();?>
        </div>
        <?php else : ?>
        <div class="no-postfound"></div>
          <?php endif;
        endif;?>
        <a class="carousel-control-prev" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev" role="button">
          <span class="carousel-control-prev-icon" aria-hidden="true"><i class="fas fa-chevron-left"></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Previous','perfect-blogging' );?></span>
        </a>
        <a class="carousel-control-next" data-bs-target="#carouselExampleCaptions" data-bs-slide="next" role="button">
          <span class="carousel-control-next-icon" aria-hidden="true"><i class="fas fa-chevron-right"></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Next','perfect-blogging' );?></span>
        </a>
      </div>  
      <div class="clearfix"></div>
    </section> 
  <?php }?>
  <?php do_action( 'perfect_blog_after_slider' ); ?>

  <div class="below-slider my-4">
    <div class="container">
      <div class="row">
        <div class="col-md-9">
          <div class="title">
            <?php if( get_theme_mod('perfect_blog_cat_title') != ''){ ?> <h2 class="p-0"><?php echo esc_html(get_theme_mod('perfect_blog_cat_title','')); ?></h2>
            <hr class="titlehr mb-3">
            <?php }?>
            <div class="category-section row p-0">
              <?php 
                $perfect_blog_catData=  get_theme_mod('perfect_blog_category');
                if($perfect_blog_catData){
                  $page_query = new WP_Query(array( 'category_name' => esc_html($perfect_blog_catData,'perfect-blogging')));?>
                  <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
                    <div class="col-lg-4 col-md-6 image-sec"> 
                      <div class="imagebox">
                        <?php if(has_post_thumbnail()) { ?><?php the_post_thumbnail(); ?><?php } ?>
                      </div>
                      <div class="contentbox w-100 my-0 mx-auto">
                        <a href="<?php the_permalink(); ?>"><h3 class="my-0 mx-auto text-uppercase p-3"><?php the_title(); ?></h3><span class="screen-reader-text"><?php the_title(); ?></span></a>
                      </div>
                    </div>
                  <?php endwhile;
                  wp_reset_postdata();
                } ?>
            </div>
          </div>
          <hr>
          <div class="category-post my-4 wow fadeInLeft">
            <?php 
            $perfect_blog_catData=  get_theme_mod('perfect_blogging_category_post');
            if($perfect_blog_catData){
              $page_query = new WP_Query(array( 'category_name' => esc_html($perfect_blog_catData,'perfect-blogging')));?>
              <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
                <div class="main-cat-box row mb-5">
                  <?php if(has_post_thumbnail()) { ?>
                    <div class="box-image col-md-6">
                      <?php the_post_thumbnail(); ?>
                    </div>
                  <?php } ?>
                  <div class="overlay <?php if(has_post_thumbnail()) { ?>col-md-6"<?php } else { ?>col-md-12"<?php } ?>>
                    <a href="<?php the_permalink(); ?>"><h4 class="p-0"><?php the_title(); ?></h4><span class="screen-reader-text"><?php the_title(); ?></span></a>
                    <div class="metabox py-2 mb-1">
                      <span class="entry-author me-2"><i class="fas fa-user"></i><a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' )) ); ?>"><?php the_author(); ?></a></span>
                      <span class="entry-date me-2"><i class="fas fa-calendar-alt"></i><a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day)); ?>"><?php echo esc_html( get_the_date() ); ?><span class="screen-reader-text"><?php echo esc_html( get_the_date() ); ?></span></a></span>     
                      <span class="entry-comments me-2"><i class="fas fa-comments"></i> <?php comments_number( __('0 Comment', 'perfect-blogging'), __('0 Comments', 'perfect-blogging'), __('% Comments', 'perfect-blogging') ); ?> </span>
                    </div>
                    <p class="mb-2"><?php the_excerpt(); ?></p>
                    <?php if( get_theme_mod( 'perfect_blogging_category_button_text', 'Read Complete Post') != '') { ?>
                      <div class="read-comp">
                        <a href="<?php echo esc_url( get_permalink() );?>"><?php echo esc_html( get_theme_mod('perfect_blogging_category_button_text',__('Read Complete Post', 'perfect-blogging')) ); ?><span class="more p-2"><i class="fas fa-long-arrow-alt-right"></i></span><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('perfect_blogging_category_button_text',__('Read Complete Post', 'perfect-blogging')) ); ?></span></a>
                      </div>
                    <?php } ?>
                  </div>
                </div>
              <?php endwhile;
              wp_reset_postdata();
            }?>
          </div>
          <div id="content-ts" class="entry-content">
            <?php while ( have_posts() ) : the_post(); ?>
              <?php the_content(); ?>
            <?php endwhile; // end of the loop. ?>
          </div>
        </div>
        <div id="sidebar" class="col-lg-3 col-md-3 wow fadeInRight">
          <?php if (is_active_sidebar('home-page')) : ?>
          <?php dynamic_sidebar('home-page'); ?>
          <?php else : ?>
            <aside id="existing-posts" role="complementary" aria-label="<?php esc_attr_e( 'homepagesidebar', 'perfect-blogging' ); ?>" class="widget">
              <h3 class="widget-title"><?php esc_html_e('Newsletter', 'perfect-blogging'); ?></h3>
              <form action="#" method="post" class="newsletter-form">
                <input type="text" name="newsletter-name" id="newsletter-name" placeholder="<?php esc_attr_e('Name', 'perfect-blogging'); ?>" required>
                <input type="email" name="newsletter-email" id="newsletter-email" placeholder="<?php esc_attr_e('Email', 'perfect-blogging'); ?>" required>
                <button type="submit" class="btn"><?php esc_html_e('Subscribe Now', 'perfect-blogging'); ?></button>
              </form>
            </aside>
          <?php endif; ?>
        </div>
      </div>
    </div>
  </div>

  <?php do_action( 'perfect_blog_after_post_section' ); ?>
</main>

<?php get_footer(); ?>