96 lines
4.5 KiB
PHP
96 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* 商品分类归档模板
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
get_header();
|
|
|
|
$term = get_queried_object();
|
|
$paged = max(1, (int) get_query_var('paged'));
|
|
$shop = class_exists('AKSRT_Shop') ? AKSRT_Shop::get_instance() : null;
|
|
$view = $shop ? $shop->get_product_archive_view([
|
|
'taxonomy' => 'aksrt_product_cat',
|
|
'term_id' => $term->term_id,
|
|
'paged' => $paged,
|
|
]) : ['products' => [], 'term' => null, 'total' => 0, 'max_pages' => 0];
|
|
|
|
$products = $view['products'];
|
|
$total = $view['total'];
|
|
$max_pages = $view['max_pages'];
|
|
$term_name = $term->name ?? '';
|
|
$term_desc = $term->description ?? '';
|
|
?>
|
|
|
|
<main id="main-content" class="site-main content-shell" tabindex="-1">
|
|
<?php if (function_exists('aksrt_breadcrumbs')) aksrt_breadcrumbs(); ?>
|
|
|
|
<div class="aksrt-product-archive container">
|
|
<header class="aksrt-product-archive__header">
|
|
<div class="aksrt-product-archive__eyebrow"><?php esc_html_e('商城商品', 'aksrt'); ?></div>
|
|
<h1 class="aksrt-product-archive__title"><?php echo esc_html($term_name); ?></h1>
|
|
<?php if ($term_desc) : ?>
|
|
<p class="aksrt-product-archive__desc"><?php echo esc_html($term_desc); ?></p>
|
|
<?php endif; ?>
|
|
<p class="aksrt-product-archive__count"><?php printf(esc_html__('共 %d 件商品', 'aksrt'), $total); ?></p>
|
|
</header>
|
|
|
|
<?php if (!empty($products)) : ?>
|
|
<div class="aksrt-product-archive__grid" id="aksrt-product-grid">
|
|
<?php foreach ($products as $product) : ?>
|
|
<article class="aksrt-product-card">
|
|
<a href="<?php echo esc_url($product['permalink']); ?>" class="aksrt-product-card__link">
|
|
<?php if ($product['image']) : ?>
|
|
<div class="aksrt-product-card__image">
|
|
<img src="<?php echo esc_url($product['image']); ?>" alt="<?php echo esc_attr($product['title']); ?>"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
|
|
</div>
|
|
<?php else : ?>
|
|
<div class="aksrt-product-card__image aksrt-product-card__image--placeholder">
|
|
<i class="fas fa-image"></i>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="aksrt-product-card__body">
|
|
<h3 class="aksrt-product-card__title"><?php echo esc_html($product['title']); ?></h3>
|
|
<?php if ($product['excerpt']) : ?>
|
|
<p class="aksrt-product-card__excerpt"><?php echo esc_html(wp_trim_words($product['excerpt'], 15)); ?></p>
|
|
<?php endif; ?>
|
|
<div class="aksrt-product-card__footer">
|
|
<span class="aksrt-product-card__price">¥<?php echo esc_html(number_format($product['price'], 2)); ?></span>
|
|
<?php if ($product['sales'] > 0) : ?>
|
|
<span class="aksrt-product-card__sales"><?php printf(esc_html__('已售 %d', 'aksrt'), $product['sales']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<?php if ($max_pages > 1) : ?>
|
|
<nav class="aksrt-product-archive__pagination" aria-label="<?php esc_attr_e('商品分页', 'aksrt'); ?>">
|
|
<?php
|
|
echo paginate_links([
|
|
'total' => $max_pages,
|
|
'current' => $paged,
|
|
'prev_text' => '<i class="fas fa-chevron-left"></i>',
|
|
'next_text' => '<i class="fas fa-chevron-right"></i>',
|
|
]);
|
|
?>
|
|
</nav>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<div class="aksrt-product-archive__empty">
|
|
<i class="fas fa-box-open"></i>
|
|
<p><?php esc_html_e('该分类下暂无商品', 'aksrt'); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<?php
|
|
wp_enqueue_script('aksrt-product-archive', get_template_directory_uri() . '/assets/js/product-archive.js', [], AKSRT_VERSION, true);
|
|
get_footer();
|