<?php
/**
 * Lists recent posts on the static front page without using Reading → Posts page.
 *
 * @package express-movers
 */

$per_page = apply_filters( 'express_movers_front_recent_posts_per_page', -1 );
if ( 0 === $per_page ) {
	return;
}

$recent = new WP_Query(
	array(
		'post_type'           => 'post',
		'post_status'         => 'publish',
		'posts_per_page'      => $per_page,
		'ignore_sticky_posts' => true,
		'no_found_rows'       => ( -1 !== $per_page ),
	)
);

if ( ! $recent->have_posts() ) {
	wp_reset_postdata();
	return;
}
?>

<section class="recent-posts-section blog-div container p-2 mt-5 mb-5" aria-label="<?php esc_attr_e( 'Recent posts', 'express-movers' ); ?>">
	<div class="banner-head mb-4">
		<div class="center-div">
			<h2><?php esc_html_e( 'Recent Posts', 'express-movers' ); ?></h2>
		</div>
	</div>
	<div class="row blog-layout">
		<div class="col-lg-8 col-md-8 col-12 front-post">
			<div class="row mainrow recent-posts-masonry g-4">
				<?php
				while ( $recent->have_posts() ) :
					$recent->the_post();
					?>
					<div class="col-lg-6 col-md-6 col-12 box">
						<?php get_template_part( 'template-parts/content', get_post_type() ); ?>
					</div>
					<?php
				endwhile;
				wp_reset_postdata();
				?>
			</div>
		</div>
		<div class="col-lg-4 col-md-4 col-12 blog-sidebar-col">
			<div class="sidebar-div mx-3">
				<?php
				if ( is_active_sidebar( 'sidebar-1' ) ) {
					?>
					<aside id="secondary" class="widget-area sidebar">
						<?php dynamic_sidebar( 'sidebar-1' ); ?>
					</aside>
					<?php
				} else {
					get_sidebar();
				}
				?>
			</div>
		</div>
	</div>
</section>
