Merge pull request 'fix(frontend): restore missing search hot keywords renderer' (#134) from worktree-hero-banner-chain into main

Reviewed-on: CYL/wordpress-theme-aksrt#134
This commit is contained in:
2026-07-14 23:05:50 +08:00
2 changed files with 54 additions and 0 deletions
@@ -105,6 +105,8 @@ class AKSRT_Inline_Style_Builder {
. '.aksrt-search-hot-keywords{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:12px;font-family:var(--font-ui);}'
. '.aksrt-search-hot-keywords__label{font-size:12px;color:var(--color-ink-3);}'
. '.aksrt-search-hot-keywords__list{display:flex;gap:8px;flex-wrap:wrap;}'
. '.aksrt-search-hot-keywords__item{display:inline-flex;align-items:center;padding:4px 10px;border-radius:999px;background:var(--surface-2,#f3f4f6);color:var(--color-ink-2,#374151);font-size:12px;line-height:1.4;text-decoration:none;}'
. '.aksrt-search-hot-keywords__item:hover{background:var(--color-primary,#2563eb);color:#fff;}'
. '.site-footer__copyright--extra{margin-top:8px;opacity:.78;}'
. '</style>' . "\n";
}
+52
View File
@@ -567,6 +567,58 @@ function aksrt_get_search_hot_keywords(): array {
}
endif;
if (!function_exists('aksrt_render_search_hot_keywords')):
/**
* Render hot search keyword chips.
*
* Used by header drawer, global search panel, search results, and 404.
*
* @param array<int,string>|null $keywords Optional preloaded keywords.
* @param string $class Wrapper class name.
*/
function aksrt_render_search_hot_keywords($keywords = null, string $class = 'aksrt-search-hot-keywords'): void {
if ($keywords === null) {
$keywords = aksrt_get_search_hot_keywords();
}
if (!is_array($keywords)) {
$keywords = [];
}
$items = [];
foreach ($keywords as $keyword) {
$keyword = trim(sanitize_text_field((string) $keyword));
if ($keyword !== '') {
$items[] = $keyword;
}
}
$items = array_values(array_unique($items));
if ($items === []) {
return;
}
$class = trim(sanitize_html_class(str_replace(' ', '-', $class), 'aksrt-search-hot-keywords'));
if ($class === '') {
$class = 'aksrt-search-hot-keywords';
}
$label = class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'search_popular_title')
? (string) AKSRT_Settings::search_popular_title()
: __('热门搜索', 'aksrt');
if ($label === '') {
$label = __('热门搜索', 'aksrt');
}
echo '<div class="' . esc_attr($class) . '">';
echo '<span class="' . esc_attr($class . '__label') . '">' . esc_html($label) . '</span>';
echo '<div class="' . esc_attr($class . '__list') . '">';
foreach ($items as $keyword) {
$url = add_query_arg('s', rawurlencode($keyword), home_url('/'));
echo '<a class="' . esc_attr($class . '__item') . '" href="' . esc_url($url) . '">' . esc_html($keyword) . '</a>';
}
echo '</div></div>';
}
endif;
if (!function_exists('aksrt_search_history_enabled')):
/**
* 是否启用搜索历史