
<?php

    if (newsweek_setting('newsweek_enable_newsticker_section', true) == true ) :

        $args = array(
            'post_type' => 'post',
            'posts_per_page' => intval(newsweek_setting('newsweek_news_ticker_limit', 5)),
            'orderby' => esc_attr(newsweek_setting('newsweek_news_ticker_order', 'date')),
            'order' => esc_attr(newsweek_setting('newsweek_news_ticker_sort_order', 'desc')),
        );

        if ( is_numeric(newsweek_setting('newsweek_news_ticker_category')) ) :
            $args['cat'] = newsweek_setting('newsweek_news_ticker_category');
        endif;

        $news_ticker = new WP_Query($args);
        $news_ticker_enabled = newsweek_setting('newsweek_enable_news_ticker_only_first_page_pagination', false);

        if (
            $news_ticker->have_posts() &&
            (
                (
                    $news_ticker_enabled == true && 
                    get_query_var('paged') <= 1
                ) ||
                $news_ticker_enabled == false
            )
        ) : 

    ?>

        <div class="news-ticker container">

            <div class="row">

                <div class="col-md-12">

                    <div class="news-ticker-carousel newsticker-<?php echo esc_attr(newsweek_setting('newsweek_news_ticker_style', 'light-style')); ?>">

                        <div class="news-ticker-title"><?php echo esc_html(newsweek_setting('newsweek_news_ticker_title', __( 'HOT', 'newsweek' )));?></div>

                        <div class="news-ticker-carousel-inner">

                            <div class="news-ticker-marquee-init">

                                <?php

                                    while ($news_ticker->have_posts()) : $news_ticker->the_post();

                                        echo '<a href="' . esc_url(get_permalink()).'">';

                                        echo '<span class="circle-marq">';

                                        if ('' != get_the_post_thumbnail() ) : 

                                            the_post_thumbnail(array(40, 40));
                                        
                                        else :

                                            $thumbnailIMG = get_template_directory_uri() . '/assets/images/placeholders/news-ticker/placeholder-40x40.jpg';
                                            echo '<img src="' . esc_url($thumbnailIMG) . '" alt="' . esc_attr(get_the_title()) . '">';

                                        endif;

                                        echo '</span>';

                                        echo esc_html(get_the_title());

                                        echo '</a>';

                                    endwhile;
                                    wp_reset_postdata();

                                ?>

                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    <?php

        endif;

    endif;

?>