<?php
	//Check if display slider
	$tg_blog_slider = kirki_get_option('tg_blog_slider');

	if(!empty($tg_blog_slider) && !is_search() && !is_category() && !is_tag() && !is_archive())
	{
		$order = 'DESC';
		if(THEMEDEMO)
		{
			$order = 'ASC';
		}
	
		//Get post featured category
		$args = array(
			'orderby' => 'date',
			'order' => $order,
			'post_type' => 'post',
			'meta_key' => '_thumbnail_id',
			'suppress_filters' => false,
		);
		
		//Check if filter slider posts by selected category
		$tg_blog_slider_cat = kirki_get_option('tg_blog_slider_cat');
		if(!empty($tg_blog_slider_cat))
		{
			$args['cat'] = $tg_blog_slider_cat;
		}
		
		//Check slider post items
		$tg_blog_slider_items = kirki_get_option('tg_blog_slider_items');
		if(!empty($tg_blog_slider_items) && is_numeric($tg_blog_slider_items))
		{
			$args['posts_per_page'] = $tg_blog_slider_items;
		}
		else
		{
			$args['posts_per_page'] = 5;
		}
		
		query_posts($args);
		
		wp_enqueue_script("letsblog-flexslider-js", get_template_directory_uri()."/js/flexslider/jquery.flexslider-min.js", false, THEMEVERSION, true);
		wp_enqueue_script("letsblog-script-gallery-flexslider", get_template_directory_uri()."/templates/script-slider-flexslider.php", false, THEMEVERSION, true);
?>
	<div id="post_featured_slider" class="slider_wrapper">
		<div class="flexslider" data-height="550">
			<ul class="slides">
	<?php
		//Display slide content
		if (have_posts()) : while (have_posts()) : the_post();
			//Get post featured image
			$slide_ID = get_the_ID();
			$image_url = array();
						
			if(has_post_thumbnail($slide_ID, 'large'))
			{
			    $image_id = get_post_thumbnail_id($slide_ID);
			    $image_url = wp_get_attachment_image_src($image_id, 'original', true);
			}
			
			if(isset($image_url[0]) && !empty($image_url[0]))
			{
	?>
			<li>
				<a href="<?php echo get_permalink($slide_ID); ?>">
					<div class="slider_image" style="background-image:url('<?php echo esc_url($image_url[0]); ?>');">
						<div class="slide_post">
							<div class="slide_post_date"><?php echo date_i18n(THEMEDATEFORMAT, get_the_time('U')); ?></div>
							<h2><?php the_title(); ?></h2>
						</div>
					</div>
				</a>
			</li>
	<?php
			}
			
		endwhile; endif;
	?>
			</ul>
		</div>
	</div>
<?php	
		wp_reset_query();
	} //End if display slider
?>