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

40 lines
1.1 KiB
PHP

<?php
/**
* Home Module · FAQ
*
* config: { title?, items: [{ q, a }], columns? }
*
* FAQ 手风琴模块。
*/
defined('ABSPATH') || exit;
$cfg = get_query_var('aksrt_module_config', []);
if (!is_array($cfg)) $cfg = [];
$title = (string) ($cfg['title'] ?? '');
$items = isset($cfg['items']) && is_array($cfg['items']) ? $cfg['items'] : [];
$columns = max(1, min(3, (int) ($cfg['columns'] ?? 1)));
if (empty($items)) return;
?>
<section class="home-module home-module--faq 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__faq-grid" style="column-count:<?php echo esc_attr((string) $columns); ?>">
<?php foreach ($items as $i => $item) :
$q = (string) ($item['q'] ?? '');
$a = (string) ($item['a'] ?? '');
if ($q === '') continue;
?>
<details class="aksrt-faq-item">
<summary class="aksrt-faq-item__question"><?php echo esc_html($q); ?></summary>
<div class="aksrt-faq-item__answer"><?php echo wp_kses_post($a); ?></div>
</details>
<?php endforeach; ?>
</div>
</section>