<?php

/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package RealEstate Press
 */
$realestate_press_categories = get_the_category();
if ($realestate_press_categories) {
	$realestate_press_category = $realestate_press_categories[mt_rand(0, count($realestate_press_categories) - 1)];
} else {
	$realestate_press_category = '';
}
?>
<div class="col-lg-4 mb-4">
	<article id="post-<?php the_ID(); ?>" <?php post_class('realestate-press-grid-item'); ?>>
		<div class="grid-blog-item">
			<?php if (has_post_thumbnail()) : ?>
				<div class="grid-img has-grid-img">
					<a href="<?php the_permalink(); ?>">
						<?php the_post_thumbnail(); ?>
					</a>
					<?php if ('post' === get_post_type() && !empty($realestate_press_category)) : ?>
						<a class="blog-categrory img-grid-cat" href="<?php echo esc_url(get_category_link($realestate_press_category)); ?>"><?php echo esc_html($realestate_press_category->name); ?></a>
					<?php endif; ?>
				</div>
			<?php endif; ?>
			<div class="grid-deatls px-3 py-4">
				<?php if ('post' === get_post_type() && !empty($realestate_press_category) && !has_post_thumbnail()) : ?>
					<a class="blog-categrory" href="<?php echo esc_url(get_category_link($realestate_press_category)); ?>"><?php echo esc_html($realestate_press_category->name); ?></a>
				<?php endif; ?>

				<?php the_title('<h2 class="entry-title grid-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>'); ?>
				<?php the_excerpt(); ?>

				<a class="read-more-btn" href="<?php the_permalink(); ?>"><?php esc_html_e('Read More ', 'realestate-press'); ?></a>
			</div>
		</div>
	</article><!-- #post-<?php the_ID(); ?> -->
</div>