<?php 
/**
 * Template part for displaying Breaking News Section
 *
 *@package DarkMag
 */
    $breaking_news_section_title           = darkmag_get_option( 'breaking_news_section_title' );
    $breaking_news_content_type            = darkmag_get_option( 'breaking_news_content_type' );
    $number_of_breaking_news_items         = darkmag_get_option( 'number_of_breaking_news_items' );
    $breaking_news_category                = darkmag_get_option( 'breaking_news_category' );

    if( $breaking_news_content_type == 'breaking_news_post' ) :
        for( $i=1; $i<=$number_of_breaking_news_items; $i++ ) :
            $breaking_news_posts[] = darkmag_get_option( 'breaking_news_post_'.$i );
        endfor;
    endif;
    ?>

    <?php if( !empty($breaking_news_section_title) ):?>
        <div class="section-header">
            <h2 class="section-title"><?php echo esc_html($breaking_news_section_title);?></h2>
        </div><!-- .section-header -->
    <?php endif;?>
    
    <?php if( $breaking_news_content_type == 'breaking_news_post' ) : ?>
        <div class="section-content" data-slick='{"slidesToShow": 3, "slidesToScroll": 1, "infinite": true, "speed": 5000, "dots": false, "arrows":false, "autoplay": true, "autoplaySpeed": 0, "pauseOnHover": true, "variableWidth": true, "fade": false }'>
            <?php $args = array (
                'post_type'     => 'post',
                'posts_per_page' => absint( $number_of_breaking_news_items ),
                'post__in'      => $breaking_news_posts,
                'orderby'       =>'post__in',
                'ignore_sticky_posts' => true,
            );        
            $loop = new WP_Query($args);                        
            if ( $loop->have_posts() ) :
            $i=-1; $j=0; 
                while ($loop->have_posts()) : $loop->the_post(); $i++; $j++; 
                $class='';
                if ($i==0) {
                    $class='display-block';
                } else{
                    $class='display-none';}
                ?>                
                
                <article class="slick-item <?php echo esc_attr($class); ?>">
                    <div class="breaking-news-item">
                        <div class="featured-image" style="background-image: url('<?php the_post_thumbnail_url( 'full' ); ?>');">
                            <a href="<?php the_permalink();?>" class="post-thumbnail-link"></a>
                        </div><!-- .featured-image -->

                        <header class="entry-header">
                            <h2 class="entry-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                        </header>
                    </div><!-- .breaking-news-item -->
                </article>

                <?php endwhile; ?>
            <?php endif; ?>
            <?php wp_reset_postdata(); ?>
        </div><!-- .section-content -->

    <?php else: ?>
        <div class="section-content" data-slick='{"slidesToShow": 3, "slidesToScroll": 1, "infinite": true, "speed": 5000, "dots": false, "arrows":false, "autoplay": true, "autoplaySpeed": 0, "pauseOnHover": true, "variableWidth": true, "fade": false }'>
            <?php $args = array (
                'posts_per_page' =>absint( $number_of_breaking_news_items ),
                'post_type' => 'post',
                'post_status' => 'publish',
                'paged' => 1,
                'ignore_sticky_posts' => true,
            );
            if ( absint( $breaking_news_category ) > 0 ) {
               $args['cat'] = absint( $breaking_news_category );
            }      
            $loop = new WP_Query($args);                        
            if ( $loop->have_posts() ) :
            $i=-1; $j=0;
                while ($loop->have_posts()) : $loop->the_post(); $i++; $j++; 
                $class='';
                if ($i==0) {
                    $class='display-block';
                } else{
                    $class='display-none';}
                ?>                 
                
                <article class="slick-item <?php echo esc_attr($class); ?>">
                    <div class="breaking-news-item">
                        <div class="featured-image" style="background-image: url('<?php the_post_thumbnail_url( 'full' ); ?>');">
                            <a href="<?php the_permalink();?>" class="post-thumbnail-link"></a>
                        </div><!-- .featured-image -->

                        <header class="entry-header">
                            <h2 class="entry-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                        </header>
                    </div><!-- .breaking-news-item -->
                </article>

                <?php endwhile; ?>
            <?php endif; ?>
            <?php wp_reset_postdata(); ?>
        </div><!-- .section-content -->
    <?php endif;