<?php
/**
 * Template part for displaying front page introduction.
 *
 * @package Nostalgic Blog
 */

// Banner Section.
$banner_section = get_theme_mod( 'nostalgic_blog_banner_section_enable', false );

if ( false === $banner_section ) {
	return;
}

$content_ids = array();

$posts_grid_content_type = get_theme_mod( 'nostalgic_blog_banner_section_content_type', 'post' );

if ( $posts_grid_content_type === 'post' ) {

	for ( $i = 1; $i <= 7; $i++ ) {
		$content_ids[] = get_theme_mod( 'nostalgic_blog_banner_section_post_' . $i );
	}

	$args = array(
		'post_type'           => 'post',
		'posts_per_page'      => absint( 7 ),
		'ignore_sticky_posts' => true,
	);
	if ( ! empty( array_filter( $content_ids ) ) ) {
		$args['post__in'] = array_filter( $content_ids );
		$args['orderby']  = 'post__in';
	} else {
		$args['orderby'] = 'date';
	}

} else {
	$cat_content_id = get_theme_mod( 'nostalgic_blog_banner_section_category' );
	$args           = array(
		'cat'            => $cat_content_id,
		'posts_per_page' => absint( 7 ),
	);
}

$query = new WP_Query( $args );
if ( $query->have_posts() ) {
	?>
	<div id="nostalgic_blog_banner_section" class="frontpage banner-navigation banner-section">
		<div class="banner-section-wrapper adore-navigation">
			<?php
			$i = 1;
			while ( $query->have_posts() ) :
				$query->the_post();
				?>
				<div class="banner-item">
					<div class="post-item post-grid">
						<div class="post-item-image">
							<a href="<?php the_permalink(); ?>">
								<?php the_post_thumbnail( 'post-thumbnail' ); ?>
							</a>
						</div>
						<div class="post-item-content">
							<span class="banner-number"><?php echo absint( $i ); ?></span>
							<h3 class="entry-title">
								<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
							</h3>  
						</div>
					</div>
				</div>
				<?php
				$i++;
			endwhile;
			wp_reset_postdata();
			?>
		</div>
	</div>

	<?php
}
