chore: complete M1.1 runtime QA and release packaging
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* Post Card — reusable, handles missing thumb/excerpt/long title.
|
||||
*
|
||||
* Expects $args['post_id'] or uses global $post.
|
||||
*
|
||||
* @package XShop
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
$postId = isset($args['post_id']) ? (int) $args['post_id'] : get_the_ID();
|
||||
if (!$postId) { return; }
|
||||
$title = get_the_title($postId);
|
||||
if ($title === '') { $title = esc_html__('Untitled', 'xshop'); }
|
||||
$permalink = get_permalink($postId);
|
||||
$excerpt = has_excerpt($postId) ? get_the_excerpt($postId) : wp_trim_words(wp_strip_all_tags(get_post_field('post_content', $postId)), 22);
|
||||
$hasThumb = has_post_thumbnail($postId);
|
||||
?>
|
||||
<article <?php post_class('xshop-card'); ?>>
|
||||
<a href="<?php echo esc_url($permalink); ?>" class="xshop-card__media <?php echo $hasThumb ? '' : 'xshop-card__media--placeholder'; ?>" aria-hidden="<?php echo $hasThumb ? 'false' : 'true'; ?>" tabindex="-1">
|
||||
<?php if ($hasThumb): ?>
|
||||
<?php echo get_the_post_thumbnail($postId, 'xshop-card', ['loading' => 'lazy', 'decoding' => 'async', 'alt' => esc_attr($title)]); ?>
|
||||
<?php else: ?>
|
||||
<span><?php esc_html_e('No image', 'xshop'); ?></span>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
<div class="xshop-card__body">
|
||||
<h3 class="xshop-card__title"><a href="<?php echo esc_url($permalink); ?>"><?php echo esc_html($title); ?></a></h3>
|
||||
<div class="xshop-card__meta">
|
||||
<time datetime="<?php echo esc_attr(get_the_date('c', $postId)); ?>"><?php echo esc_html(get_the_date('', $postId)); ?></time>
|
||||
<?php
|
||||
$cats = get_the_category($postId);
|
||||
if (!empty($cats[0])) {
|
||||
echo '<span aria-hidden="true">·</span><a href="' . esc_url(get_category_link($cats[0]->term_id)) . '">' . esc_html($cats[0]->name) . '</a>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php if ($excerpt !== ''): ?>
|
||||
<p class="xshop-card__excerpt"><?php echo esc_html($excerpt); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</article>
|
||||
Reference in New Issue
Block a user