<?php
/**
 * Template part for displaying a post in archive/list views.
 *
 * @package Eronex
 * @since 0.0.1
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$excerpt_length = eronex_option( 'eronex_archive_post_excerpt_length' );
$categories     = get_the_category_list( ', ' );
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<?php if ( has_post_thumbnail() ) : ?>
		<figure class="eronex-post-thumbnail">
			<?php the_post_thumbnail( 'large' ); ?>
		</figure>
	<?php endif; ?>

	<div class="eronex-post-info">
		<?php if ( ! empty( $categories ) ) { ?>
			<div class="eronex-post-categories">
				<?php echo wp_kses_post( $categories ); ?>
			</div>
		<?php } ?>

		<h2 class="eronex-post-title"><?php the_title( sprintf( '<a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a>' ); ?></h2>

		<ul class="eronex-post-meta">
			<li class="eronex-post-meta eronex-post-author-name">
				<?php echo esc_html__( 'By', 'eronex' ); ?>
				<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ) ); ?>">
					<?php echo esc_html( get_the_author() ); ?>
				</a>
			</li>
			<li class="eronex-post-meta eronex-post-commnets">
				<a href="<?php comments_link(); ?>">
					<?php
					comments_number(
						esc_html__( 'No comments', 'eronex' ),
						esc_html__( '1 comment', 'eronex' ),
						esc_html__( '% comments', 'eronex' )
					);
					?>
				</a>
			</li>
			<li class="eronex-post-meta eronex-post-date">
				<?php the_time( get_option( 'date_format' ) ); ?>
			</li>
		</ul>

		<div class="eronex-post-content"><p><?php eronex_excerpt( $excerpt_length ); ?></p></div>

		<a class="eronex-link" href="<?php echo esc_url( get_permalink() ); ?>">
			<?php echo esc_html__( 'Read more', 'eronex' ); ?>
			<i class="hi hi-arrow-right"></i>
		</a>
	</div>
</article>
