<?php
/**
 * News card used by the posts page and native post archives.
 *
 * @package Fragrance_Trade
 */

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

$categories  = get_the_category_list( ' · ' );
$media_label = sprintf(
	/* translators: %s: news article title. */
	__( '阅读%s', 'fragrance-trade' ),
	get_the_title()
);
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'news-card' ); ?>>
	<a class="news-card-media" href="<?php the_permalink(); ?>" aria-label="<?php echo esc_attr( $media_label ); ?>">
		<?php if ( has_post_thumbnail() ) : ?>
			<?php the_post_thumbnail( 'medium_large', array( 'class' => 'img-fluid', 'loading' => 'lazy', 'decoding' => 'async' ) ); ?>
		<?php else : ?>
			<img src="<?php echo esc_url( fragrance_trade_asset_uri( 'images/placeholder-news.svg' ) ); ?>" alt="" width="1200" height="675" loading="lazy" decoding="async">
		<?php endif; ?>
	</a>
	<div class="news-card-body">
		<div class="news-meta">
			<?php if ( $categories ) : ?>
				<span class="news-categories"><?php echo wp_kses_post( $categories ); ?></span>
			<?php endif; ?>
			<time datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>"><?php echo esc_html( get_the_date() ); ?></time>
		</div>
		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
		<p><?php echo esc_html( wp_trim_words( get_the_excerpt(), 28 ) ); ?></p>
		<a class="text-link" href="<?php the_permalink(); ?>"><?php esc_html_e( '阅读全文', 'fragrance-trade' ); ?></a>
	</div>
</article>
