<?php
/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package GrShop
 */

?>
<div class="<?php if(is_active_sidebar('sidebar')):?> col-lg-6 col-md-6 col-12 <?php else :?> col-lg-4 col-md-6 col-12 <?php endif;?>   grshop-grocery-masonry-item">
	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
		<div class="grshop-grocery-single-post">
			<?php if(has_post_thumbnail()) : ?>	
			<div class="grshop-grocery-single-post__head">
				<div class="grshop-grocery-single-post__comments"><i class="fa fa-comments"></i><?php echo esc_html(get_comments_number());?></div>
				<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('grshop-grocery-blog-thumb'); ?></a>
				<?php if (!empty($grshop_grocery_categories)) :?>
				<div class="grshop-grocery-single-post__cat">
					<?php foreach ($grshop_grocery_categories as $grshop_grocery_category) :?>
						<a href="<?php echo esc_url(get_category_link($grshop_grocery_category->term_id));?>"><?php echo esc_html($grshop_grocery_category->name); ?></a>
					<?php endforeach;?>	
				</div>
				<?php endif;?>
			</div>
			<?php endif; ?>
			<div class="grshop-grocery-single-post__body">
				
				<?php if (!empty($grshop_grocery_categories) && !(has_post_thumbnail()) ) :?>
				<div class="grshop-grocery-single-post__cat">
					<?php foreach ($grshop_grocery_categories as $grshop_grocery_category) :?>
						<a href="<?php echo esc_url(get_category_link($grshop_grocery_category->term_id));?>"><?php echo esc_html($grshop_grocery_category->name); ?></a>
					<?php endforeach;?>	
				</div>
				<?php endif;?>

				<h2 class="grshop-grocery-single-post__title">
				<?php if( is_sticky()) :?><span class="grshop-grocery-sticky"><i class="fa-regular fa-note-sticky"></i></span><?php endif;?>
				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
				<!-- Post Meta -->
				<ul class="grshop-grocery-post-meta">
					<li><i class="fa fa-pencil"></i><?php grshop_grocery_posted_on(); ?></li>
					<li><i class="fa fa-user"></i><a class="grshop-grocery-post-meta__author" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>"><?php 
					grshop_grocery_posted_by(); ?></a></li>
				</ul>
				
				<div class="grshop-grocery-single-post__content"><?php the_excerpt();?></div>
				
				<div class="grshop-grocery-single-post__button">
					<a href="<?php the_permalink(); ?>" class="grshop-grocery-btn"><?php esc_html_e('View Article','grshop-grocery');?></a>
				</div>
			</div>
		</div>
	</article> <!-- #post-<?php the_ID(); ?> -->
</div>