<?php
/**
 * The template for displaying archive course.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package devoer
 */

get_header(); ?>
<?php
$courses_number_post     = themesflat_get_opt( 'courses_number_post' ) ? themesflat_get_opt( 'courses_number_post' ) : 6;
$columns                 = themesflat_get_opt( 'courses_grid_columns' );
$columns_tb              = themesflat_get_opt( 'courses_grid_columns_tablet' );
$columns_mb              = themesflat_get_opt( 'courses_grid_columns_mobile' );
$themesflat_paging_style = themesflat_get_opt( 'courses_archive_pagination_style' );
$orderby                 = themesflat_get_opt( 'courses_order_by' );
$order                   = themesflat_get_opt( 'courses_order_direction' );
$exclude                 = themesflat_get_opt( 'courses_exclude' );
$terms_slug              = wp_list_pluck( get_terms( 'courses_category', 'hide_empty=0' ), 'slug' );

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

$query_args = array(
	'post_type'      => 'courses',
	'orderby'        => $orderby,
	'order'          => $order,
	'paged'          => $paged,
	'posts_per_page' => $courses_number_post,
);
if ( ! empty( $terms_slug ) ) {
	$query_args['tax_query'] = array(
		array(
			'taxonomy' => 'courses_category',
			'field'    => 'slug',
			'terms'    => $terms_slug,
		),
	);
}

if ( ! empty( $exclude ) ) {
	if ( ! is_array( $exclude ) ) {
		$exclude = explode( ',', $exclude );
	}

	$query_args['post__not_in'] = $exclude;
}
$query         = new WP_Query( $query_args );
$item_classes  = themesflat_create_columns( $columns, $columns_tb, $columns_mb );
$sidebar       = themesflat_get_opt( 'courses_sidebar_list' );
$content_class = 'col-12';
if ( themesflat_get_opt( 'courses_layout' ) == 'sidebar-left' || themesflat_get_opt( 'courses_layout' ) == 'sidebar-right' ) {
	if ( is_active_sidebar( $sidebar ) ) {
		$main_class = 'col-lg-9';
	}
}
?>
    <div class="themesflat-courses-taxonomy">
        <div class="container">
            <div class="wrap-content-area">
                <div class="row tf-wrap-content">
                    <div class="<?php echo esc_attr( $main_class ) ?> content-wrap tf-content-wrap">
                        <div id="primary" class="content-area">
                            <main id="main" class="main-content" role="main">
                                <div class="tf-wrap-courses-post row column-<?php echo esc_attr( $columns ); ?>">
									<?php

									if ( $query->have_posts() ) {
										while ( $query->have_posts() ) : $query->the_post();
											$id                = $post->ID;
											$price             = get_post_meta( $id, 'tf_course_price', true );
											$theory_session    = get_post_meta( $id, 'tf_course_theory_session', true );
											$practical_session = get_post_meta( $id, 'tf_course_practical_session', true );
											?>
                                            <div class="item <?php echo esc_attr( $item_classes ) ?>">
                                                <div class="courses-post courses-post-style1 courses-post-<?php the_ID(); ?>">
                                                    <div class="featured-post">
														<?php
														themesflat_render_thumbnail_markup( array(
															'image_size'  => '740x460',
															'image_mode'  => 'background',
															'placeholder' => ''
														) );
														?>
                                                        <div class="price-wrap">
                                                            <sup><?php esc_html_e( '$', 'themesflat' ) ?></sup>
                                                            <span class="price"><?php echo esc_html( $price ) ?></span><?php esc_html_e( '/Person', 'themesflat' ) ?>
                                                        </div>
                                                    </div>
                                                    <div class="content">
                                                        <h2 class="title">
                                                            <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
                                                        </h2>
                                                        <div class="desc"><?php echo wp_trim_words( get_the_content(), 9, '' ); ?></div>
                                                        <div class="tf-course-addition-informartion-wrap">
                                                            <div class="tf-course-addition-informartion">
                                                                <div class="addition-informartion-item">
                                                                    <span class="label"><?php esc_html_e( 'THEORY SESSION', 'themesflat' ) ?></span>
                                                                    <span class="value"><?php echo esc_html( $theory_session ) ?></span>
                                                                </div>
                                                                <div class="addition-informartion-item">
                                                                    <span class="label"><?php esc_html_e( 'PRACTICAL SESSION', 'themesflat' ) ?></span>
                                                                    <span class="value"><?php echo esc_html( $practical_session ) ?></span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <a href="<?php echo get_the_permalink(); ?>"
                                                       class="courses-view-more">
														<?php esc_html_e( 'View Course Details', 'themesflat' ) ?>
                                                    </a>
                                                </div>
                                            </div>
										<?php
										endwhile;
									} else {
										get_template_part( 'template-parts/content', 'none' );
									}
									?>
                                </div>
								<?php
								themesflat_pagination_posttype( $query );
								wp_reset_postdata();
								?>
                            </main><!-- #main -->
                        </div><!-- #primary -->
                    </div>
					<?php
					if ( themesflat_get_opt( 'courses_layout' ) == 'sidebar-left' || themesflat_get_opt( 'courses_layout' ) == 'sidebar-right' ) :
						get_sidebar();
					endif;
					?>
                </div>
            </div>
        </div>
    </div><!-- /.themesflat-courses-taxonomy -->

<?php get_footer(); ?>