<?php
/**
 * Blog section
 *
 * This is the template for the content of blog section
 *
 * @package Theme Palace
 * @subpackage Newstation
 * @since Newstation 1.0.0
 */
$options = newstation_get_theme_options();
if( $options['world_news_section_enable'] !== false ):

$content_details = array();

$post_ids = array();

    for ( $i = 1; $i <= 4; $i++ ) {
        if ( ! empty( $options['world_news_content_post_' . $i] ) )
            $post_ids[] = $options['world_news_content_post_' . $i];
    }

    $args = array(
        'post_type'         => 'post',
        'post__in'          => ( array ) $post_ids,
        'posts_per_page'    => absint( 4 ),
        'orderby'           => 'post__in',
        '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']   = newstation_trim_content( 15 );
$page_post['url']       = get_the_permalink();
$page_post['image']  	= has_post_thumbnail() ? get_the_post_thumbnail_url( get_the_id(), 'full' ) : 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="world-news" class="relative">
    <?php if ( $options['world_news_title'] ): ?>

        <div class="section-header">
            <h2 class="section-title"><?php echo esc_html( $options['world_news_title'] ); ?></h2>
        </div><!-- .section-header -->

    <?php endif; ?>

    <div class="world-news-slider" data-slick='{"slidesToShow": 2, "slidesToScroll": 1, "infinite": true, "speed": 1000, "dots": false, "arrows":true, "autoplay": false, "draggable": true, "fade": false }'>

        <?php foreach ($content_details as $content ): ?>

            <article>
                <div class="featured-image" style="background-image: url('<?php echo esc_url( $content['image'] ) ?>');"></div>
                <div class="entry-container">
                    <div class="entry-meta">

                        <?php newstation_posted_on( $content['id'] ); ?>

                        <span class="min-read"><?php echo newstation_time_interval( $content['excerpt'] ); echo esc_html__(' min read', 'newstation'); ?></span>
                        <?php the_category( '', '', $content['id'] ); ?>
                    </div>
                    <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>
                    <div class="entry-content">
                        <p><?php echo esc_html( $content['excerpt'] ); ?></p>
                    </div>
                </div><!-- .entry-container -->
            </article>

        <?php endforeach ?>

    </div><!-- .world-news-slider -->

</div><!-- #world-news-aection -->

<?php endif; ?>