<?php 
$team_enable = get_theme_mod( 'advance_education_pro_radio_popular_courses_enable' );
if ( 'Disable' == $team_enable ) {
  return;
}
/*team*/
if( get_theme_mod('advance_education_pro_popular_courses_bgcolor') ) { 
  $about_backg = 'background-color:'.esc_attr(get_theme_mod('advance_education_pro_popular_courses_bgcolor')).';';
}elseif( get_theme_mod('advance_education_pro_popular_courses_bgimage') ){
  $about_backg = 'background-image:url(\''.esc_url(get_theme_mod('advance_education_pro_popular_courses_bgimage')).'\')';
}else{
  $about_backg = '';   
}
  $att_style="";
  $image_att = get_theme_mod( 'advance_education_pro_popular_courses_bgimage_attachment',true );
  if ( 'Scroll' == $image_att ) {
    $att_style="section_bg_scroll";
  }else{
    $att_style="section_bg_fixed";
  }  
$args = array(
  'post_type' => 'courses',
  'post_status' => 'publish',
  'createcategory'=> get_theme_mod('advance_education_pro_popular_courses_category')
);            
$new = new WP_Query($args); 
if ( defined( 'ADVANCE_EDUCATION_PRO_POSTTYPE_VERSION' ) ) :
?>
  <section id="popular_courses" style="<?php echo esc_html($about_backg); ?>" class="<?php echo esc_attr($att_style); ?>">
    <div class="container">
    <?php if(get_theme_mod('advance_education_pro_popular_courses_title') != ''){?>
      <div class="section-heading">
        <h3> 
          <?php if(get_theme_mod('advance_education_pro_title_icon')){
              ?> <i class="<?php echo esc_html(get_theme_mod('advance_education_pro_title_icon')) ?>"></i><?php
            }?>
          <?php echo esc_html(get_theme_mod('advance_education_pro_popular_courses_title')); ?></h3>
      </div>
    <?php } ?>
    <?php if(get_theme_mod('advance_education_pro_popular_courses_subtitle') != ''){?>
      <div class="section-heading">
        <p><?php echo esc_html(get_theme_mod('advance_education_pro_popular_courses_subtitle')); ?></p>
      </div>
    <?php } ?>
    <?php if ( $new->have_posts() ) : ?>
      <div class="owl-carousel">
        <?php            
          $loop_index = 0; $i=1;
          while ( $new->have_posts() ){
          $new->the_post();  ?>
          <div class="<?php if($i == 1){ echo 'active';}?>"> 
            <div class="box">
              <?php if(get_post_meta($post->ID,'custom_link',true) !='') { $custom_link = get_post_meta($post->ID,'custom_link',true); } else {
              $custom_link = get_the_permalink(); } ?>
              <a href="<?php echo esc_url($custom_link) ?>">
              <div class="image-box media">
                <?php the_post_thumbnail(); ?>
                <div class="overlay">
                    <div class="title-section">
                      <div class="title-div">
                        <p class="title"><?php the_title(); ?></p>
                      </div>
                    </div>
                </div>
                <div class="popular-courses-hover">
                   <div class="popular_courses_content">
                      <h4 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                      <?php if(get_post_meta($post->ID,'price',true)){?>
                      <p class="location"><?php echo esc_html(get_theme_mod('advance_education_pro_course_price_currency'))?><?php echo esc_html(get_post_meta($post->ID,'price',true)); }?></p>
                      <p class="subtitle"><?php $excerpt = get_the_excerpt(); echo esc_html(advance_education_pro_string_limit_words($excerpt,12)); ?></span>
                      <div class="popular_courses_details">
                      <?php if(get_post_meta($post->ID,'course_duration',true) || get_post_meta($post->ID,'apply_now',true)){?>
                      <div class="popular_course_details">
                          <?php if(get_post_meta($post->ID,'course_duration',true)){?>
                            <p class="course_details"><i class="far fa-calendar-alt"></i><span class="details_label"><?php echo esc_html_e('Course Duration:','advance-education-pro');?></span><?php echo esc_html(get_post_meta($post->ID,'course_duration',true)); ?></p><?php } ?>
                          <?php if(get_post_meta($post->ID,'degree_level',true)){?>
                            <p class="course_details"><i class="fas fa-graduation-cap"></i><span class="details_label"><?php echo esc_html_e('Degree Level:','advance-education-pro');?></span><?php echo esc_html(get_post_meta($post->ID,'degree_level',true)); ?></p>
                          <?php }?>
                          <?php if(get_post_meta($post->ID,'apply_now',true)){?>
                            <div class="apply-now"><a href="<?php echo esc_url($custom_link); ?>"class="apply"><?php echo esc_html(get_post_meta($post->ID,'apply_now',true)); ?></a></div>
                          <?php } ?>
                      </div>
                    <?php }?>
                  </div>
                </div>
                </div>
              </div>
            </a>
            </div>
          </div>
        <?php $i++; }
        wp_reset_query(); ?>
      </div>
      <?php
        else :
          echo '<h5 class="text-center">' . esc_html__( 'Create the Popular Courses to make it appear here.', 'advance-education-pro' ) . '</h5>'; 
        endif;
      ?>
    </div>
    <div class="clearfix"></div>
  </section>
<?php
else :
  echo '<h5 class="text-center">' . esc_html__( 'Please Activate Advance Education Pro Posttype and create the team to make it appear here.', 'advance-education-pro' ) . '</h5>'; 
endif; ?>