<?php
/**
* Featured Post Section
*
* This is the template for the content of fetaured post section
*
* @package Theme Palace
* @subpackage Power News
* @since Power News 1.0.0
*/

$options = power_news_get_theme_options();

if($options['featured_posts_section_enable'] !== false ):
$content_details = array();

$cats_id = ! empty( $options['featured_posts_content_category'] ) ? $options['featured_posts_content_category'] : '';
$args = array(
    'post_type'         => 'post',
    'posts_per_page'    => 3,
    'cat'               => absint( $cats_id ),
    'ignore_sticky_posts'   => true,
);

// Run The Loop.
$query = new WP_Query( $args );
if ( $query->have_posts() ) : 
    while ( $query->have_posts() ) : $query->the_post();
    $page_post['id']        = get_the_id();
    $page_post['title']     = get_the_title();
    $page_post['excerpt']   = power_news_trim_content( 25 );
    $page_post['auth_id']   = get_the_author_meta('ID');
    $page_post['url']       = get_the_permalink();
    $page_post['image'] = has_post_thumbnail() ? get_the_post_thumbnail_url( get_the_id(), 'post-thumbnail' ) : get_template_directory_uri() . '/assets/uploads/no-featured-image-590x650.jpg';

// Push to the main array.
array_push( $content_details, $page_post );
endwhile;
endif;
wp_reset_postdata();
?>
<div id="power_news_featured_posts_section" class="featured-posts-section relative">
    <?php if ( is_customize_preview()):
        power_news_section_tooltip( 'featured-posts-section-class' );
    endif; ?>
    <div class="featured-post-slider" data-slick='{"slidesToShow": 1, "slidesToScroll": 1, "infinite": true, "speed": 1000, "dots": false, "arrows": true, "autoplay": false, "draggable": true, "fade": false }'>
        <?php foreach ( $content_details as $content ) : ?>
            <article style="background-image: url('<?php echo esc_url( $content['image'] ); ?>');">
                <div class="entry-container">
                    <div class="entry-meta">
                            <span class="cat-links">
                                <?php the_category( '', '', $content['id'] ); ?>
                            </span><!-- .cat-links -->
                        <?php power_news_posted_on( $content['id'] ); ?>
                    </div><!-- .entry-meta -->

                    <header class="entry-header">
                        <h2 class="entry-title"><a href="<?php echo esc_url( $content['url'] ); ?>"><?php echo esc_html( $content['title'] ); ?></a></h2>
                    </header>
                    <?php echo power_news_author( $content['auth_id'] ); ?>
                </div><!-- .entry-container -->
            </article>
    <?php endforeach; ?>
    </div><!-- .featured-slider -->
</div><!-- #power_featured_posts_section -->
<?php endif; ?>
