<?php
$trending_query = new WP_Query( $trending_args );
if ( $trending_query->have_posts() ) {
	$trending_title = get_theme_mod( 'macro_news_trending_posts_title', __( 'Trending Posts', 'macro-news' ) );
	$advertisement_image = get_theme_mod( 'macro_news_banner_advertisement_image', '' );
	$advertisement_url   = get_theme_mod( 'macro_news_banner_advertisement_url', '' );
	?>
	<div class="trending-part">
		<div class="trending-wrap">
			<div class="section-header">
				<?php if ( ! empty( $trending_title ) ) : ?>
					<h3 class="section-title"><?php echo esc_html( $trending_title ); ?></h3>
				<?php endif; ?>
			</div>
			<div class="trending-wrapper">
				<?php
				$i = 1;
				while ( $trending_query->have_posts() ) :
					$trending_query->the_post();
					?>
					<div class="mag-post-single banner-gird-single has-image list-design">
						<div class="mag-post-img">
							<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'post-thumbnail' ); ?></a>
							<span class="trending-no"><?php echo absint( $i ); ?></span>
						</div>
						<div class="mag-post-detail">
							<div class="mag-post-category">
								<?php macro_news_categories_list(); ?>
							</div>
							<h4 class="mag-post-title">
								<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
							</h4>
						</div>
					</div>
					<?php
					$i++;
				endwhile;
				wp_reset_postdata();
				?>
			</div>
		</div>
		<?php if ( ! empty( $advertisement_image ) ) { ?>
			<div class="banner-adver">
				<a href="<?php echo esc_url( $advertisement_url ); ?>">
					<img src="<?php echo esc_url( $advertisement_image ); ?>" alt="<?php esc_attr_e( 'Advertisement Image', 'macro-news' ); ?>">
				</a>
			</div>		
		<?php } ?>
	</div>
	<?php
}
