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

<main role="main" id="maincontent">
  <?php do_action( 'advance_fitness_gym_above_slider' ); ?>
  
  <?php if( get_theme_mod( 'advance_fitness_gym_slider_hide', true) != '' || get_theme_mod( 'advance_fitness_gym_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('advance_fitness_gym_slider_speed_option', 3000)); ?>"> 
        <?php $advance_fitness_gym_slider_pages = array();
          for ( $count = 1; $count <= 4; $count++ ) {
            $mod = intval( get_theme_mod( 'advance_fitness_gym_slider_page' . $count ));
            if ( 'page-none-selected' != $mod ) {
              $advance_fitness_gym_slider_pages[] = $mod;
            }
          }
          if( !empty($advance_fitness_gym_slider_pages) ) :
            $args = array(
              'post_type' => 'page',
              'post__in' => $advance_fitness_gym_slider_pages,
              '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"';}?>>
              <a href="<?php the_permalink(); ?>"><?php if(has_post_thumbnail()){
                  the_post_thumbnail();
              } else{?>
                <img src="<?php echo esc_url(get_template_directory_uri()); ?>/theme-block-pattern/images/banner.png" alt="" />
              <?php } ?></a>
              <div class="carousel-caption wow zoomIn">
                <?php if(get_theme_mod('advance_fitness_gym_slider_title_Show_hide',true) != '' || get_theme_mod('advance_fitness_gym_slider_content_Show_hide',true) != ''){ ?>
                  <div class="inner_carousel text-center p-3">
                    <?php if( get_theme_mod('advance_fitness_gym_slider_title_Show_hide',true) != ''){ ?>
                      <h1><?php the_title(); ?></h1>
                    <?php } ?>
                    <?php if( get_theme_mod('advance_fitness_gym_slider_content_Show_hide',true) != ''){ ?>
                      <p><?php $advance_fitness_gym_excerpt = get_the_excerpt(); echo esc_html( advance_fitness_gym_string_limit_words( $advance_fitness_gym_excerpt, esc_attr(get_theme_mod('advance_fitness_gym_slider_excerpt_length','20')))); ?></p>
                    <?php } ?>
                  </div>
                <?php } ?>
              </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 w-auto h-auto" aria-hidden="true"><i class="fas fa-chevron-left"></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Previous','advance-fitness-gym' );?></span>
        </a>
        <a class="carousel-control-next" data-bs-target="#carouselExampleCaptions" data-bs-slide="next" role="button">
          <span class="carousel-control-next-icon w-auto h-auto" aria-hidden="true"><i class="fas fa-chevron-right"></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Next','advance-fitness-gym' );?></span>
        </a>
      </div>
      <div class="clearfix"></div>
    </section>
  <?php } ?>

  <?php do_action( 'advance_fitness_gym_below_slider' ); ?>

  <?php if( get_theme_mod( 'advance_fitness_gym_product_service') == true) { ?>
    <section id="fitness-content" class="my-5">
      <div class="container">
        <div class="fitnes-post p-3">      
          <div class="row">
            <?php 
              $advance_fitness_gym_catData = get_theme_mod('advance_fitness_gym_product_service');
              if($advance_fitness_gym_catData){              
              $page_query = new WP_Query(array( 'category_name' => esc_html( $advance_fitness_gym_catData ,'advance-fitness-gym')));?>
              <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
                <div class="col-lg-3 col-md-3">
                  <div class="service-border text-center">
                    <?php the_post_thumbnail('full'); ?>
                    <a href="<?php the_permalink(); ?>"><strong class="text-uppercase my-2"><?php the_title(); ?></strong></a>
                    <p><?php $advance_fitness_gym_excerpt = get_the_excerpt(); echo esc_html( advance_fitness_gym_string_limit_words( $advance_fitness_gym_excerpt,10 ) ); ?></p>
                  </div>
                </div>
              <?php endwhile;
              wp_reset_postdata();
            }
            ?>
          </div>
        </div>
      </div>
    </section>
  <?php } ?>

  <?php do_action( 'advance_fitness_gym_below_services' ); ?>

  <?php if( get_theme_mod( 'advance_fitness_gym_single_post') != '') { ?>
    <section id="fitness-togym" class="my-5">
      <div class="container">
        <div class="fitness-single-post">      
          <?php
            $args = array( 
              'p' => get_theme_mod('advance_fitness_gym_single_post',''),
              'post_type' => 'post'
            );
            $query = new WP_Query( $args );
            if ( $query->have_posts() ) :
              while ( $query->have_posts() ) : $query->the_post(); ?>
                <div class="row">
                  <div class="col-lg-6 col-md-6">
                    <div class="img-box wow fadeInLeft">
                      <?php the_post_thumbnail('full'); ?>
                    </div>
                  </div>
                  <div class="col-lg-6 col-md-6">
                    <div class="single-content wow fadeInRight ">
                      <h2 class="text-uppercase"><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2>
                      <hr class="wlcm-hr mt-0">
                      <p><?php $advance_fitness_gym_excerpt = get_the_excerpt(); echo esc_html( advance_fitness_gym_string_limit_words( $advance_fitness_gym_excerpt,70 ) ); ?></p>
                      <?php if( get_theme_mod( 'advance_fitness_gym_category_button_text','Read More' ) != '') { ?>
                        <div class="know-btn">
                          <a href="<?php echo esc_url( get_permalink() );?>" class="blogbutton-small py-2 px-3" title="<?php esc_attr_e( 'Read More', 'advance-fitness-gym' ); ?>"><?php echo esc_html( get_theme_mod('advance_fitness_gym_category_button_text',__('Read More', 'advance-fitness-gym')) ); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('advance_fitness_gym_category_button_text',__('Read More', 'advance-fitness-gym')) ); ?></span>
                          </a>
                        </div>
                      <?php } ?>
                    </div>
                  </div>
                </div>
              <?php endwhile; 
              wp_reset_postdata();?>
            <?php else : ?>
              <div class="no-postfound"></div>
            <?php
          endif; ?>
        </div>
      </div>
    </section>
  <?php }?>

  <?php do_action( 'advance_fitness_gym_below_welcome_section' ); ?>

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

<?php get_footer(); ?>