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

42 lines
1.3 KiB
PHP

<?php
/**
* Home Module · Button Group
*
* config: { title?, buttons: [{ label, url, style?, icon? }], align? }
*
* 按钮组模块,用于 CTA 引导。
*/
defined('ABSPATH') || exit;
$cfg = get_query_var('aksrt_module_config', []);
if (!is_array($cfg)) $cfg = [];
$title = (string) ($cfg['title'] ?? '');
$buttons = isset($cfg['buttons']) && is_array($cfg['buttons']) ? $cfg['buttons'] : [];
$align = sanitize_key((string) ($cfg['align'] ?? 'center'));
if (empty($buttons)) return;
?>
<section class="home-module home-module--button-group container" style="text-align:<?php echo esc_attr($align); ?>">
<?php if ($title !== '') : ?>
<h2 class="home-module__title"><?php echo esc_html($title); ?></h2>
<?php endif; ?>
<div class="home-module__buttons">
<?php foreach ($buttons as $btn) :
$label = (string) ($btn['label'] ?? '');
$url = (string) ($btn['url'] ?? '#');
$style = sanitize_key((string) ($btn['style'] ?? 'primary'));
$icon = (string) ($btn['icon'] ?? '');
if ($label === '') continue;
?>
<a href="<?php echo esc_url($url); ?>" class="aksrt-btn aksrt-btn--<?php echo esc_attr($style); ?>">
<?php if ($icon !== '') : ?>
<i class="<?php echo esc_attr($icon); ?>" aria-hidden="true"></i>
<?php endif; ?>
<span><?php echo esc_html($label); ?></span>
</a>
<?php endforeach; ?>
</div>
</section>