<?php
/**
 * Featured Post Slider
 *
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
// Get our Featured Content posts
$slider_posts = pmthemes_get_featured_content();

// Check if there is Featured Content
if ( empty( $slider_posts ) and current_user_can( 'edit_theme_options' ) ) : ?>

	<p class="frontpage-slider-empty-posts">
		<?php _e('There is no featured content to be displayed in the slider. To set up the slider, go to Appearance -> Customize, and add a tag under Tag Name in the Featured Content section. The slideshow will then display all posts which are tagged with that keyword.', 'pmthemes'); ?>
	</p>
	
<?php
	return;
endif;

// Limit the number of words in slideshow post excerpts
add_filter('excerpt_length', 'pmthemes_slideshow_excerpt_length');

// Display Slider
?>
	<div id="frontpage-slider-wrap" class="clearfix">
		<div id="frontpage-slider" class="pmsflexslider">
			<ul class="pmsslides">

		<?php foreach ( $slider_posts as $post ) : setup_postdata( $post ); ?>

			<li id="slide-<?php the_ID(); ?>" class="pmsslide">

			<?php // Display Post Thumbnail or default thumbnail
				if( '' != get_the_post_thumbnail() ) :

					the_post_thumbnail('slider_image', array('class' => 'slide-image'));

				else: ?>

					<img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/default-slider-image.png" class="slide-image wp-post-image" alt="default-image" />

			<?php endif;?>

				<div class="slide-entry clearfix">
					<h2 class="slide-title"><a href="<?php esc_url(the_permalink()) ?>" rel="bookmark"><?php the_title(); ?></a></h2>
					<?php $theme_options = pmthemes_theme_options();
					if ( isset($theme_options['show_slider_content']) and $theme_options['show_slider_content'] == true ) : ?>
					<div class="slide-content"><?php the_excerpt(); ?></div>
					<a href="<?php esc_url(the_permalink()) ?>" class="slide-more-link"><?php _e('Read more &raquo;', 'pmthemes'); ?></a>
					<?php endif; ?>
				</div>

			</li>

		<?php endforeach; ?>

			</ul>
		</div>
		<div class="frontpage-slider-controls"></div>
	</div>
<?php
// Remove excerpt filter
remove_filter('excerpt_length', 'pmthemes_slideshow_excerpt_length');

// Reset Postdata
wp_reset_postdata();

?>