<?php
/**
 * Template Name: EasySite Blog
 *
 * @package EasySite_Pro
 */

get_header();

$query = new WP_Query( array(
	'post_type'      => 'post',
	'posts_per_page' => get_option( 'posts_per_page', 10 ),
	'paged'          => max( 1, get_query_var( 'paged' ) ),
) );
?>

<div class="easysite-page-hero easysite-section">
	<div class="easysite-container">
		<h1><?php the_title(); ?></h1>
	</div>
</div>

<div class="easysite-container easysite-content-area <?php echo easysite_get_mod( 'easysite_show_sidebar', true ) ? 'has-sidebar' : ''; ?>">
	<div class="easysite-primary">
		<?php if ( $query->have_posts() ) : ?>
			<div class="easysite-posts-grid">
				<?php
				$first = true;
				while ( $query->have_posts() ) :
					$query->the_post();
					?>
					<article <?php post_class( $first ? 'easysite-post-card is-featured' : 'easysite-post-card' ); ?>>
						<?php if ( has_post_thumbnail() ) : ?>
							<a href="<?php the_permalink(); ?>" class="easysite-post-thumb"><?php the_post_thumbnail( 'easysite-card' ); ?></a>
						<?php endif; ?>
						<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
						<p class="easysite-meta"><?php echo esc_html( get_the_date() ); ?></p>
						<p><?php echo esc_html( wp_trim_words( get_the_excerpt(), 24 ) ); ?></p>
						<a class="easysite-read-more" href="<?php the_permalink(); ?>"><?php esc_html_e( 'Read more', 'easysite-pro' ); ?></a>
					</article>
					<?php
					$first = false;
				endwhile;
				?>
			</div>
		<?php else : ?>
			<p><?php esc_html_e( 'No blog posts yet. Create your first post from the WordPress dashboard.', 'easysite-pro' ); ?></p>
		<?php endif;
		wp_reset_postdata();
		?>
	</div>
	<?php if ( easysite_get_mod( 'easysite_show_sidebar', true ) ) : ?>
		<?php get_sidebar(); ?>
	<?php endif; ?>
</div>

<?php get_footer(); ?>
