<?php 
$team_enable = get_theme_mod( 'advance_education_pro_radio_our_courses_enable' );
if ( 'Disable' == $team_enable ) {
  return;
}
/*team*/
if( get_theme_mod('advance_education_pro_our_courses_bgcolor') ) { 
  $about_backg = 'background-color:'.esc_attr(get_theme_mod('advance_education_pro_our_courses_bgcolor')).';';
}elseif( get_theme_mod('advance_education_pro_our_courses_bgimage') ){
  $about_backg = 'background-image:url(\''.esc_url(get_theme_mod('advance_education_pro_our_courses_bgimage')).'\')';
}else{
  $about_backg = '';   
}
$args = array(
  'post_type' => 'courses',
  'post_status' => 'publish',
  'createcategory'=> get_theme_mod('advance_education_pro_our_courses_category')
);
$att_style="";
$image_att = get_theme_mod( 'advance_education_pro_our_courses_bgimage_attachment',true );
if ( 'Scroll' == $image_att ) {
  $att_style="section_bg_scroll";
}else{
  $att_style="section_bg_fixed";
}             
$new = new WP_Query($args); 
if ( defined( 'ADVANCE_EDUCATION_PRO_POSTTYPE_VERSION' ) ) :
?>
  <section id="our_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_our_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_our_courses_title')); ?></h3>
      </div>
    <?php } ?>
    <?php if(get_theme_mod('advance_education_pro_our_courses_subtitle') != ''){?>
      <div class="section-heading">
        <p><?php echo esc_html(get_theme_mod('advance_education_pro_our_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>
              <div class="our_courses_details">
                <div class="our_courses_content">
                  <h4 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                  <p class="subtitle"><?php $excerpt = get_the_excerpt(); echo esc_html(advance_education_pro_string_limit_words($excerpt,12)); ?></p>
                      <div class="popular_courses_details">                           
                        <?php if(get_post_meta($post->ID,'meta-image',true) || get_post_meta($post->ID,'degree_level',true) || get_post_meta($post->ID,'students',true) || get_post_meta('date') || get_post_meta($post->ID,'price',true)){?>
                      <div class="row popular_course_details">
                        <div class="col-lg-8 col-md-6 col-sm-6 col-8">
                          <?php 
                            $custom_url = '';
                            $img = get_post_meta(get_the_ID(), 'meta-image', true);
                            if(get_post_meta(get_the_ID(), 'meta-url', true !='')){  $custom_url = get_post_meta(get_the_ID(), 'meta-url', true); }
                          ?>
                          <a href="<?php if($custom_url != ''){ echo esc_url($custom_url); } else { the_permalink(); } ?>"></a>
                          <?php if(get_post_meta($post->ID,'professors-image') != '') {?>
                            <img class="professors-image" src="<?php echo esc_url($img); ?>">
                          <?php } ?>
                          <div class="name">
                            <?php if(get_post_meta($post->ID,'professors_name',true) != '') {?>
                              <span class="professors-name"><?php echo esc_html(get_post_meta($post->ID,'professors_name',true))?></span>
                            <?php } ?>
                          </div>
                        </div>
                        <div class="col-lg-4 col-md-6 col-sm-6 col-4">
                          <?php if(get_post_meta($post->ID,'price',true)){?>
                            <p class="price"><?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>
                          <?php }?>
                        </div>
                      </div>
                      <div class="row mt-3">
                         <div class="col-lg-6 col-md-6 col-sm-6 col-6">
                          <?php if(get_post_meta($post->ID,'students',true)){?>
                            <p class="students"><?php echo esc_html(get_post_meta($post->ID,'students',true)); ?></p>
                          <?php }?>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-6 col-6">
                          <?php if(get_post_meta($post->ID,'date',true)){?>
                            <p class="date"><?php echo esc_html(get_post_meta($post->ID,'date',true)); ?></p>
                          <?php }?>
                        </div>
                      </div>
                    <?php }?>
                  </div>
            </div>
          </div>
        </a>
      </div>
    </div>
        <?php $i++; }
        wp_reset_query(); ?>
      </div>
      <?php
        else :
          echo '<h5 class="text-center">' . esc_html__( 'Create Our 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 Our Courses to make it appear here.', 'advance-education-pro' ) . '</h5>'; 
endif; ?>