<?php

/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Colorful Blog
 */
$colorful_blog_blog_layout = get_theme_mod('colorful_blog_blog_layout', 'rightside');
if ($colorful_blog_blog_layout == 'fullwidth' || !is_active_sidebar('sidebar-1')) {
	$colorful_blog_grid = 4;
} else {
	$colorful_blog_grid = 6;
}
$colorful_blog_categories = get_the_category();
if ($colorful_blog_categories) {
	$colorful_blog_category = $colorful_blog_categories[mt_rand(0, count($colorful_blog_categories) - 1)];
} else {
	$colorful_blog_category = '';
}
?>
<div class="col-lg-<?php echo esc_attr($colorful_blog_grid); ?> grid-item mb-5">
	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
		<div class="grid-item-post">
			<?php if (has_post_thumbnail()) : ?>
				<div class="grid-item-img">
					<a class="grid-item-img-link" href="<?php the_permalink(); ?>">
						<?php the_post_thumbnail(); ?>
					</a>
				</div>
			<?php endif; ?>
			<div class="grid-item-details">
				<?php if ($colorful_blog_category) : ?>
					<a class="catimg-top" href="<?php echo esc_url(get_category_link($colorful_blog_category)); ?>"><?php echo esc_html($colorful_blog_category->name); ?></a>
				<?php endif; ?>
				<?php the_title('<h2 class="grid-item-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>'); ?>
				<?php if ('post' === get_post_type()) :
				?>
					<div class="entry-meta">
						<?php
						colorful_blog_posted_by();
						?>
					</div><!-- .entry-meta -->
				<?php endif; ?>
				<?php the_excerpt(); ?>
				<a class="grid-item-btn" href="<?php the_permalink(); ?>">
					<i class="fas fa-arrow-right"></i>
				</a>
			</div>
		</div>
	</article><!-- #post-<?php the_ID(); ?> -->
</div>