<?php
/**
 * Template Name: Custom home page
 */
get_header(); ?>

<main id="maincontent" role="main">
  <?php 
    $modern_blogger_archive_year  = get_the_time('Y'); 
    $modern_blogger_archive_month = get_the_time('m'); 
    $modern_blogger_archive_day   = get_the_time('d'); 
  ?>
  <!-- slider section --> 
  <?php if( get_theme_mod( 'modern_blogger_show_slider', false ) != '' || get_theme_mod( 'modern_blogger_slider_responsive', false ) != '' ) {?>
    <section id="slider-section" class=""> 
      <div class="owl-carousel">
        <?php $modern_blogger_catData=  get_theme_mod('modern_blogger_slider_category');
          if($modern_blogger_catData){
          $page_query = new WP_Query(array( 'category_name' => esc_html( $modern_blogger_catData ,'modern-blogger')));?>
            <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
              <div class="slider-box wow fadeInDown" data-wow-delay="0.4s" data-wow-duration="1.4s">
                <?php the_post_thumbnail(); ?>
                <div class="slider-content wow zoomIn" data-wow-delay="0.4s" data-wow-duration="1.2s">
                  <div class="inner-content">
                    <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' )) ); ?>"><span class="entry-author"> <?php the_author(); ?></span><span class="screen-reader-text"><?php the_author(); ?></span>
                    </a>
                    <span class="seperator px-2"><?php echo esc_html(get_theme_mod('modern_blogger_meta_field_separator_slider', '.'));?></span>
                    <a href="<?php echo esc_url( get_day_link( $modern_blogger_archive_year, $modern_blogger_archive_month, $modern_blogger_archive_day)); ?>"><span class="entry-date"><?php echo esc_html( get_the_date() ); ?></span><span class="screen-reader-text"><?php echo esc_html( get_the_date() ); ?></span>
                    </a>
                    <span class="seperator px-2"><?php echo esc_html(get_theme_mod('modern_blogger_meta_field_separator_slider', '.'));?></span> 
                      <i class="fas fa-thumbs-up" aria-hidden="true"></i><span class="entry-comments"> <?php comments_number( __('0 Comments','modern-blogger'), __('0 Comments','modern-blogger'), __('% Comments','modern-blogger') ); ?></span> 
                  </div>
                  <?php if ( get_theme_mod('modern_blogger_slider_title',true) != '' ) {?>
                    <h1 class="pt-0"><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('modern_blogger_slider_content',true) != '' ) {?>
                    <p class=""><?php $modern_blogger_excerpt = get_the_excerpt(); echo esc_html( modern_blogger_string_limit_words( $modern_blogger_excerpt,esc_attr(get_theme_mod('modern_blogger_slider_excerpt_number','25')))); ?>
                    </p>
                  <?php }?>
                  <?php if(get_theme_mod('modern_blogger_slider_button',true)) {?>  
                    <?php if ( get_theme_mod('modern_blogger_slider_button_label', 'Read More') != '' ) {?>
                      <a href="<?php the_permalink(); ?>" class="read-more"><?php echo esc_html( get_theme_mod('modern_blogger_slider_button_label',__('Read More','modern-blogger')) ); ?><i class="fas fa-arrow-right ms-1"></i><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('modern_blogger_slider_button_label',__('Read More','modern-blogger')) ); ?></span>
                      </a>
                    <?php } ?>  
                  <?php }?>  
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          } 
        ?>
      </div>
    </section>
  <?php }?>
  <!-- Services section -->
  <section id="category-section" class="mt-lg-5 mt-md-5 mt-4"> 
    <div class="container">
    <?php if( get_theme_mod( 'modern_blogger_show_service_section', false ) ) {?>
        <div class="row">
            <div class="col-lg-6 col-md-12 position-relative wow zoomInLeft" data-wow-delay="0.4s" data-wow-duration="1.3s">
                <?php
                $modern_blogger_postData1 = get_theme_mod('modern_blogger_services_section_setting');
                if($modern_blogger_postData1){
                  $args = array( 'name' => esc_html($modern_blogger_postData1 ,'modern-blogger'));
                  $query = new WP_Query( $args );
                  if ( $query->have_posts() ) :
                    while ( $query->have_posts() ) : $query->the_post(); ?>
                      <div class="abt-image w-100">
                        <?php the_post_thumbnail(); ?>
                      </div>
                      <div class="mid-content">
                        <?php if( get_theme_mod( 'modern_blogger_metafields_date',true) != '') { ?>
                          <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' )) ); ?>"><span class="entry-author"> <?php the_author(); ?></span><span class="screen-reader-text"><?php the_author(); ?></span>
                          </a>
                          <span class="seperator px-2"><?php echo esc_html(get_theme_mod('modern_blogger_meta_field_separator_service', '.'));?></span><a href="<?php echo esc_url( get_day_link( $modern_blogger_archive_year, $modern_blogger_archive_month, $modern_blogger_archive_day)); ?>"><span class="entry-date"><?php echo esc_html( get_the_date() ); ?></span><span class="screen-reader-text"><?php echo esc_html( get_the_date() ); ?></span></a>
                        <?php }?>
                        <span class="seperator px-2"><?php echo esc_html(get_theme_mod('modern_blogger_meta_field_separator_service', '.'));?></span> 
                        <i class="fas fa-thumbs-up" aria-hidden="true"></i><span class="entry-comments pe-3"> <?php comments_number( __('0 Comments','modern-blogger'), __('0 Comments','modern-blogger'), __('% Comments','modern-blogger') ); ?></span> 
                      </div>
                      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h2>     
                      <p class=""><?php $modern_blogger_excerpt = get_the_excerpt(); echo esc_html( modern_blogger_string_limit_words( $modern_blogger_excerpt, 25)); ?></p>
                      <a href="<?php the_permalink(); ?>" class="read-full-text"><?php echo esc_html('READ FULL STORY','modern-blogger'); ?><span class="screen-reader-text"><?php echo esc_html('READ FULL STORY','modern-blogger'); ?></span></a>
                    <?php endwhile; 
                    wp_reset_postdata();?>
                  <?php else : ?>
                    <div class="no-postfound"></div>
                  <?php
                endif; }?>
            </div>
        
      <!-- post middle -->
          <div class="col-lg-4 col-md-8 mt-lg-0 mt-md-3 mt-3 wow zoomIn" data-wow-delay="0.5s" data-wow-duration="1.5s">
            <?php 
              $modern_blogger_catData=  get_theme_mod('modern_blogger_category1');
              if($modern_blogger_catData){
              $page_query = new WP_Query(array( 'category_name' => esc_html($modern_blogger_catData,'modern-blogger')));?>
              <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
              <div class="middle-part position-relative">
                <div class="abt-img-box w-100 "><?php if(has_post_thumbnail()) { ?><?php the_post_thumbnail(); ?><?php } ?></div>
                <div class="post-middle-content">
                  <?php if( get_theme_mod( 'modern_blogger_metafields_date',true) != '') { ?>
                    <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' )) ); ?>"><span class="entry-author"> <?php the_author(); ?></span><span class="screen-reader-text"><?php the_author(); ?></span></a>
                    <span class="seperator px-1"><?php echo esc_html(get_theme_mod('modern_blogger_meta_field_separator_service', '.'));?></span> <a href="<?php echo esc_url( get_day_link( $modern_blogger_archive_year, $modern_blogger_archive_month, $modern_blogger_archive_day)); ?>"><span class="entry-date"><?php echo esc_html( get_the_date() ); ?></span><span class="screen-reader-text"><?php echo esc_html( get_the_date() ); ?></span></a>
                      <?php }?>
                    <span class="seperator px-1"><?php echo esc_html(get_theme_mod('modern_blogger_meta_field_separator_service', '.'));?></span> 
                    <i class="fas fa-thumbs-up" aria-hidden="true"></i><span class="entry-comments"> <?php comments_number( __('0 Comments','modern-blogger'), __('0 Comments','modern-blogger'), __('% Comments','modern-blogger') ); ?></span>
                </div>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?><span class="screen-reader-text"><?php the_title(); ?></span></a>
                </h2>         
                <a href="<?php the_permalink(); ?>" class="read-full-text"><?php echo esc_html('READ FULL STORY','modern-blogger'); ?><span class="screen-reader-text"><?php echo esc_html('READ FULL STORY','modern-blogger'); ?></span></a>
                <div class="clearfix"></div>
              </div>
              <?php endwhile;
              wp_reset_postdata();   
              }        
            ?>  
          </div>
          
      <!-- select last post -->
          <div class="col-lg-2 col-md-4 mt-lg-0 mt-md-3 mb-4">
            <?php
              $modern_blogger_postData1 = get_theme_mod('modern_blogger_add_post');
              if($modern_blogger_postData1){
                $args = array( 'name' => esc_html($modern_blogger_postData1 ,'modern-blogger'));
                $query = new WP_Query( $args );
                if ( $query->have_posts() ) :
                  while ( $query->have_posts() ) : $query->the_post(); ?>
                    <div class="last-post">
                      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?><span class="screen-reader-text"><?php the_title(); ?></span></a>
                      </h2> 
                      <div class="add-post position-relative wow zoomIn" data-wow-delay="0.4s" data-wow-duration="1.2s">
                        <?php the_post_thumbnail(); ?>         
                      </div>    
                      <a href="<?php the_permalink(); ?>" class="read-full"><?php echo esc_html('READ FULL','modern-blogger'); ?><span class="screen-reader-text"><?php echo esc_html('READ FULL','modern-blogger'); ?></span></a> 
                    </div>
                  <?php endwhile; 
                  wp_reset_postdata();?>
                <?php else : ?>
                  <div class="no-postfound"></div>
                <?php
              endif; }?>
          </div>
        </div>
      </div>
    <?php }?>
  </section>
  <?php do_action('modern_blogger_after_category_section'); ?>

  <div class="container">
    <?php while ( have_posts() ) : the_post(); ?>
      <div class="entry-content"><?php the_content(); ?></div>
    <?php endwhile; // end of the loop. ?>
  </div>
</main>

<?php get_footer(); ?>