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

get_header(); ?>

<main id="skip-content">
  <?php if(get_theme_mod('audio_player_top_slider_setting',1) == 1){ ?>
    <section id="top-slider" >
        <?php $audio_player_slide_pages = array();
          for ( $audio_player_count = 1; $audio_player_count <= 3; $audio_player_count++ ) {
            $audio_player_mod = intval( get_theme_mod( 'audio_player_top_slider_page' . $audio_player_count ));
            if ( 'page-none-selected' != $audio_player_mod ) {
              $audio_player_slide_pages[] = $audio_player_mod;
            }
          }
          if( !empty($audio_player_slide_pages) ) :
            $audio_player_args = array(
              'post_type' => 'page',
              'post__in' => $audio_player_slide_pages,
              'orderby' => 'post__in'
            );
            $audio_player_query = new WP_Query( $audio_player_args );
            if ( $audio_player_query->have_posts() ) :
              $i = 1;
        ?>
        <div class="owl-carousel" role="listbox">
          <?php  while ( $audio_player_query->have_posts() ) : $audio_player_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/images/slider.png" alt="" />
              <?php } ?>
              <div class="slider-inner-box">
                <?php if(get_theme_mod('audio_player_slider_heading') != ''){ ?>
                  <h3 class="heading"><?php echo esc_html(get_theme_mod('audio_player_slider_heading')); ?></h3>
                <?php }?>
                <?php if(get_theme_mod('audio_player_slider_title_setting',1) == 1){ ?>
                  <h2 class="m-0"><?php the_title(); ?></h2>
                <?php }?>
                <?php if(get_theme_mod('audio_player_slider_content_setting',1) == 1){ ?>
                  <p class="content mt-3"><?php echo esc_html( wp_trim_words( get_the_content(),esc_attr(get_theme_mod('audio_player_slider_excerpt_length', 70)) )); ?><p>
                <?php }?>
                <?php if(get_theme_mod('audio_player_slider_button_setting',1) == 1 && get_theme_mod('audio_player_slider_button_text','READ MORE') != ''){ ?>
                  <div class="slide-btn mt-4"><a href="<?php the_permalink(); ?>"><?php esc_html_e(get_theme_mod('audio_player_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 if(get_theme_mod('audio_player_player_shortcode') != ''){ ?>
      <div class="player">
        <div class="container">
          <?php echo do_shortcode(get_theme_mod('audio_player_player_shortcode')); ?>
        </div>
      </div>
      <?php }?>
    </section>
  <?php }?>

  <section class="feature-sec py-5">
    <div class="container">
      <div class=" text-center headings">
        <?php if(get_theme_mod('audio_player_feature_long_heading') != ''){ ?>
          <h3><?php echo esc_html(get_theme_mod('audio_player_feature_long_heading','')); ?></h3>
        <?php }?>
        <?php if(get_theme_mod('audio_player_feature_short_heading') != ''){ ?>
          <p><?php echo esc_html(get_theme_mod('audio_player_feature_short_heading','')); ?></p>
        <?php }?>
      </div>
        <div class="owl-carousel">
        <?php
          $audio_player_feature_cat = get_theme_mod('audio_player_feature_sec_category','');
          $audio_player_feature_per_page = get_theme_mod('audio_player_feature_per_page',4);
          if($audio_player_feature_cat){
            $audio_player_page_query5 = new WP_Query(array( 'category_name' => esc_html($audio_player_feature_cat,'audio-player'),'post_per_page' => esc_attr( $audio_player_feature_per_page )));
            $i=1;
            while( $audio_player_page_query5->have_posts() ) : $audio_player_page_query5->the_post(); ?>
              <div class="box-category">
                <div class="box-image-cat">
                  <a href="<?php the_permalink(); ?>"><?php if(has_post_thumbnail()){
                  the_post_thumbnail();
                  } else{?>
                  <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/slider.png" alt="" />
                <?php } ?></a>
                </div>
                <p class="content mt-3"><?php echo esc_html( wp_trim_words( get_the_content(), 30 )); ?><p>
                <?php if ( get_post_meta($post->ID, 'audio_player_button_url') != "" || get_post_meta($post->ID, 'audio_player_episode_1') != "" || get_post_meta($post->ID, 'audio_player_text_1') != ""  ) {?>
                  <div class="row mb-3">
                    <div class="col-lg-1 col-md-2 col-sm-2 col-2 box-icon align-self-center">
                      <?php if( get_post_meta($post->ID, 'audio_player_button_url', true) ) {?>
                        <a href="<?php echo esc_url(get_post_meta($post->ID,'audio_player_button_url',true)); ?>"><i class="fas fa-play"></i></a>
                        <?php }?>
                    </div>
                      <div class="col-lg-11 col-md-10 col-sm-10 col-10 align-self-center">
                        <?php if( get_post_meta($post->ID, 'audio_player_episode_1', true) ) {?>
                        <p class="text p-0 m-0"><?php echo esc_html(get_post_meta($post->ID,'audio_player_episode_1',true)); ?></p>
                        <?php }?>
                        <?php if( get_post_meta($post->ID, 'audio_player_text_1', true) ) {?>
                        <h6 class=" heading p-0 m-0"><?php echo esc_html(get_post_meta($post->ID,'audio_player_text_1',true)); ?></h6>
                        <?php }?>
                      </div>
                  </div>
                <?php }?>
                <?php if ( get_post_meta($post->ID, 'audio_player_button_url_2') != "" || get_post_meta($post->ID, 'audio_player_episode_2') != "" || get_post_meta($post->ID, 'audio_player_text_2') != ""  ) {?>
                  <div class="row mb-3">
                    <div class="col-lg-1 col-md-2 col-sm-2 col-2 box-icon align-self-center">
                      <?php if( get_post_meta($post->ID, 'audio_player_button_url_2', true) ) {?>
                        <a href="<?php echo esc_url(get_post_meta($post->ID,'audio_player_button_url_2',true)); ?>"><i class="fas fa-play"></i></a>
                      <?php }?>
                    </div>
                    <div class="col-lg-11 col-md-10 col-sm-10 col-10  align-self-center">
                      <?php if( get_post_meta($post->ID, 'audio_player_episode_2', true) ) {?>
                        <p class="text p-0 m-0"><?php echo esc_html(get_post_meta($post->ID,'audio_player_episode_2',true)); ?></p>
                      <?php }?>
                      <?php if( get_post_meta($post->ID, 'audio_player_text_2', true) ) {?>
                        <h6 class="heading p-0 m-0"><?php echo esc_html(get_post_meta($post->ID,'audio_player_text_2',true)); ?></h6>
                      <?php }?>
                    </div>
                  </div>
                <?php }?>
                <div class="feature-box-btn text-start mb-2">
                  <a href="<?php the_permalink(); ?>"><?php esc_html_e('READ MORE','audio-player'); ?></a>
                </div>
              </div>
            <?php $i++; endwhile;
          wp_reset_postdata();
        } ?>
      </div>
    </div>
  </section>
  <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(); ?>