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

<main id="content">
  <?php if( get_option('chiropractor_therapy_slider_arrows', false) !== 'off'){ ?>
    <section id="slider">
      <div class="owl-carousel">
        <?php
          $slider_category=  get_theme_mod('chiropractor_therapy_post_setting');if($slider_category){
          $page_query = new WP_Query(array( 

              'category_name' => esc_html($slider_category ,'chiropractor-therapy'),

              'posts_per_page' => get_theme_mod('chiropractor_therapy_slider_count')

            ));?>
            <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
            <div class="slide-box">
              <?php if(has_post_thumbnail()){ ?>
                <img src="<?php the_post_thumbnail_url('full'); ?>"/>
              <?php } else{?>
                <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/header-img.png" alt="" />
              <?php } ?>
              <div class="slide-inner-box slider-inner">
                <?php if( get_theme_mod('chiropractor_therapy_slide_heading') != ''){ ?>
                  <h3><?php echo esc_html(get_theme_mod('chiropractor_therapy_slide_heading','')); ?></h3>
                <?php }?>
                <h2 class="slider-title"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h2> 
                <?php if( get_option('chiropractor_therapy_slider_excerpt_show_hide',true) != 'off'){ ?>
                  <p class="slider-excerpt mt-4"><?php echo wp_trim_words(get_the_content(), get_theme_mod('chiropractor_therapy_slider_excerpt_count',30) );?></p>
                <?php } ?>             
              </div>
            </div>
            <?php endwhile;
          wp_reset_postdata();
        }?>
      </div>
    </section>
  <?php }?>
  <?php if( get_option('chiropractor_therapy_course_enable', false) !== 'off'){ ?>
    <section id="home-courses" class="py-5">
      <div class="container">
        <?php if( get_theme_mod('chiropractor_therapy_course_heading_text') != ''){ ?>
          <h6 class="text-center"><?php echo esc_html(get_theme_mod('chiropractor_therapy_course_heading_text','')); ?></h6>
        <?php }?>
        <?php if( get_theme_mod('chiropractor_therapy_course_heading') != ''){ ?>
          <h3 class="text-center mb-4"><?php echo esc_html(get_theme_mod('chiropractor_therapy_course_heading','')); ?></h3>
        <?php }?>
        <div class="row">
            <?php
              $courses_category=  get_theme_mod('chiropractor_therapy_courses_setting');
              $chiropractor_therapy_course_order = get_theme_mod('chiropractor_therapy_course_order_type','ascending');
              if($courses_category){
                $chiropractor_therapy_args = array( 

                  'category_name' => esc_html($courses_category ,'chiropractor-therapy'),

                  'posts_per_page' => get_theme_mod('chiropractor_therapy_service_count'),

                  'order'         =>'ASC'

                );
                // Adjust ordering based on user selection
                if ($chiropractor_therapy_course_order == 'descending') {
                  $chiropractor_therapy_args['order'] = 'DESC';
                } else if ($chiropractor_therapy_course_order == 'a-to-z') {
                  $chiropractor_therapy_args['orderby'] = 'title';
                  $chiropractor_therapy_args['order'] = 'ASC';
                } else if ($chiropractor_therapy_course_order == 'z-to-a') {
                  $chiropractor_therapy_args['orderby'] = 'title';
                  $chiropractor_therapy_args['order'] = 'DESC';
                }
                $page_query = new WP_Query($chiropractor_therapy_args);?>
                <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
                  <div class="col-lg-4 col-md-6 col-sm-6 wow zoomIn">
                    <div class="courses-box mb-4">
                      <?php if(has_post_thumbnail()){ ?>
                        <?php the_post_thumbnail(); ?>
                      <?php } ?>
                      <div class="teacher-box">
                        <?php if( get_post_meta($post->ID, 'chiropractor_therapy_teacher', true) ) {?>
                          <span><i class="fas fa-user me-2"></i><?php echo esc_html(get_post_meta($post->ID,'chiropractor_therapy_teacher',true)); ?></span>
                        <?php }?>
                      </div>
                      <h4 class="mb-0"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                      <?php if( get_post_meta($post->ID, 'chiropractor_therapy_student', true) || get_post_meta($post->ID, 'chiropractor_therapy_lesson', true) ) {?>
                        <div class="courses-inner-box">
                          <span class="me-4 me-md-5">
                            <?php if( get_post_meta($post->ID, 'chiropractor_therapy_student', true) ) {?>
                              <span><i class="fas fa-user me-2"></i><?php echo esc_html(get_post_meta($post->ID,'chiropractor_therapy_student',true)); ?></span>
                            <?php }?>
                          </span>
                          <span>
                            <?php if( get_post_meta($post->ID, 'chiropractor_therapy_lesson', true) ) {?>
                              <span><i class="fas fa-book me-2"></i><?php echo esc_html(get_post_meta($post->ID,'chiropractor_therapy_lesson',true)); ?></span>
                            <?php }?>
                          </span>
                        </div>
                      <?php }?>
                    </div>
                  </div>
                <?php endwhile;
              wp_reset_postdata();
            }?>
        </div>
      </div>
    </section>
  <?php }?>
  <section id="custom-page-content" <?php if ( have_posts() && trim( get_the_content() ) !== '' ) echo 'class="pt-3"'; ?>>
    <div class="container">
      <?php while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
      <?php endwhile; ?>
    </div>
  </section>
</main>

<?php get_footer(); ?>