<?php

/**
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-3.0.txt
 */

function newsweek_get_newsticker() {

	$html = '';

	$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;

	$newsticker = new WP_Query($args);

	if ($newsticker->have_posts()) : 

		$html .= '<div class="ticker-section">';

		$html .= '<div class="ticker">';

		$html .= '<strong><span>' . newsweek_setting('newsweek_news_ticker_title', esc_html__( 'HOT', 'newsweek')) . '</span></strong>';

		$html .= '<ul>';

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

			$html .= '<li><a href="' . esc_url(get_permalink()).'">' . esc_html(get_the_title()).'</a></li>';

		endwhile;

		$html .= '</ul>';

		$html .= '</div>';
		$html .= '</div>';
	
	endif;
	wp_reset_postdata();

	return $html;

}

?>