<?php

/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package  News Axis
 */
$news_axis_categories = get_the_category();
if ($news_axis_categories) {
	$news_axis_category = $news_axis_categories[mt_rand(0, count($news_axis_categories) - 1)];
} else {
	$news_axis_category = '';
}
$news_axis_readmore = get_theme_mod('news_axis_readmore');
?>
<div class="col-lg-4 mb-4 grid-item">
	<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">
				<a href="<?php echo esc_url(get_permalink()); ?>" rel="bookmark">
					<h2 class="grid-item-title entry-title" data-text="<?php echo esc_attr(get_the_title()); ?>">
						<?php the_title(); ?>
					</h2>
				</a>
				<?php the_excerpt(); ?>
				<?php if (!empty($news_axis_readmore)): ?>
					<a href="<?php echo esc_url(get_permalink()); ?>" class="nax-redmore">
						<?php echo esc_html($news_axis_readmore); ?>
					</a>
				<?php endif; ?>
				<?php if ('post' === get_post_type()) : ?>
					<div class="entry-meta grid-meta">
						<div class="grid-item-topmeta">
							<?php if ($news_axis_category) : ?>
								<div class="post-category-theme">
									<a class="catimg-top"
										href="<?php echo esc_url(get_category_link($news_axis_category)); ?>"><?php echo esc_html($news_axis_category->name); ?>
									</a>
								</div>
							<?php endif; ?>

							<div class="post-by_theme">
								<?php news_axis_posted_by(); ?>
							</div>

						</div>
						<span class="grid-meta-date">
							<?php echo get_the_date(); ?>
						</span>
					</div>
				<?php endif; ?>
			</div>
		</div>

	</article><!-- #post-<?php the_ID(); ?> -->
</div>