Files
wordpress-theme-aksrt/templates/parts/home-modules/module-product_showcase.php
T

55 lines
2.0 KiB
PHP

<?php
/**
* Home Module · Product Showcase
*
* config: { title?, products: [{ title, desc, image, price?, url? }], columns? }
*
* 产品展示模块,用于商城/资源推荐。
*/
defined('ABSPATH') || exit;
$cfg = get_query_var('aksrt_module_config', []);
if (!is_array($cfg)) $cfg = [];
$title = (string) ($cfg['title'] ?? '');
$products = isset($cfg['products']) && is_array($cfg['products']) ? $cfg['products'] : [];
$columns = max(1, min(4, (int) ($cfg['columns'] ?? 3)));
if (empty($products)) return;
?>
<section class="home-module home-module--product-showcase container">
<?php if ($title !== '') : ?>
<header class="home-module__header">
<h2 class="home-module__title"><?php echo esc_html($title); ?></h2>
</header>
<?php endif; ?>
<div class="home-module__product-grid" style="grid-template-columns:repeat(<?php echo esc_attr((string) $columns); ?>, 1fr)">
<?php foreach ($products as $product) :
$p_title = (string) ($product['title'] ?? '');
$p_desc = (string) ($product['desc'] ?? '');
$p_image = (string) ($product['image'] ?? '');
$p_price = (string) ($product['price'] ?? '');
$p_url = (string) ($product['url'] ?? '');
if ($p_title === '') continue;
?>
<a href="<?php echo esc_url($p_url ?: '#'); ?>" class="aksrt-product-card">
<?php if ($p_image !== '') : ?>
<div class="aksrt-product-card__image">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $p_image); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($p_title); ?>">
</div>
<?php endif; ?>
<div class="aksrt-product-card__body">
<h3 class="aksrt-product-card__title"><?php echo esc_html($p_title); ?></h3>
<?php if ($p_desc !== '') : ?>
<p class="aksrt-product-card__desc"><?php echo esc_html($p_desc); ?></p>
<?php endif; ?>
<?php if ($p_price !== '') : ?>
<span class="aksrt-product-card__price"><?php echo esc_html($p_price); ?></span>
<?php endif; ?>
</div>
</a>
<?php endforeach; ?>
</div>
</section>