
<?php

    if (urbanews_setting('urbanews_enable_newsticker_section', true) == true ) :

        $args = array(
            'post_type' => 'post',
            'posts_per_page' => intval(urbanews_setting('urbanews_news_ticker_limit', 5)),
            'orderby' => esc_attr(urbanews_setting('urbanews_news_ticker_order', 'date')),
            'order' => esc_attr(urbanews_setting('urbanews_news_ticker_sort_order', 'desc')),
        );

        if ( is_numeric(urbanews_setting('urbanews_news_ticker_category')) ) :
            $args['cat'] = urbanews_setting('urbanews_news_ticker_category');
        endif;

        $news_ticker = new WP_Query($args);
        $news_ticker_enabled = urbanews_setting('urbanews_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
            )
        ) : 

        $image_layout = urbanews_setting('urbanews_news_ticker_images_layout', 'round');

    ?>

        <div class="news-ticker container">

            <div class="row">

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

                    <div class="news-ticker-carousel <?php echo esc_attr($image_layout);?>_images newsticker-<?php echo esc_attr(urbanews_setting('urbanews_news_ticker_style', 'light-style')); ?>">

                        <div class="news-ticker-title"><?php echo esc_html(urbanews_setting('urbanews_news_ticker_title', __( 'HOT', 'urbanews' )));?></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_stylesheet_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;

?>