<?php

/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Affiliate Eye
 */
$affiliate_eye_blog_layout = get_theme_mod('affiliate_eye_blog_layout', 'rightside');
if ($affiliate_eye_blog_layout == 'fullwidth' || !is_active_sidebar('sidebar-1')) {
	$affiliate_eye_grid = 4;
} else {
	$affiliate_eye_grid = 6;
}
$affiliate_eye_categories = get_the_category();
if ($affiliate_eye_categories) {
	$affiliate_eye_category = $affiliate_eye_categories[mt_rand(0, count($affiliate_eye_categories) - 1)];
} else {
	$affiliate_eye_category = '';
}
?>
<div class="col-lg-<?php echo esc_attr($affiliate_eye_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>
					<?php if ($affiliate_eye_category) : ?>
						<a class="catimg-top" href="<?php echo esc_url(get_category_link($affiliate_eye_category)); ?>"><?php echo esc_html($affiliate_eye_category->name); ?></a>
					<?php endif; ?>
				</div>
			<?php else : ?>
				<?php if ($affiliate_eye_category) : ?>
					<a class="cat-noimg-top" href="<?php echo esc_url(get_category_link($affiliate_eye_category)); ?>"><?php echo esc_html($affiliate_eye_category->name); ?></a>
				<?php endif; ?>
			<?php endif; ?>
			<div class="grid-item-details">
				<?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
						affiliate_eye_posted_by();
						?>
					</div><!-- .entry-meta -->
				<?php endif; ?>
				<?php the_excerpt(); ?>
				<a class="grid-item-btn" href="<?php the_permalink(); ?>">
					<?php esc_html_e('Continue Reading ', 'affiliate-eye'); ?>
				</a>
			</div>
		</div>
	</article><!-- #post-<?php the_ID(); ?> -->
</div>