feat(navigation): hard-switch to Zibll navigation and Font Awesome 5

This commit is contained in:
2026-08-18 20:46:21 +08:00
parent 3c3ddac8be
commit a0b84977a2
630 changed files with 101647 additions and 11293 deletions
+114 -291
View File
@@ -1,313 +1,136 @@
<?php
/**
* Search results template.
* Zibll-contract search results template.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
get_header();
global $wp_query;
$search_query = get_search_query();
$loop_query = $wp_query;
$search_state = function_exists('aksrt_get_search_form_state')
? aksrt_get_search_form_state()
: [
'type' => 'post',
'types' => ['post' => __('文章', 'aksrt')],
'category_id' => 0,
'category_enabled' => false,
'categories' => [],
];
$has_search_query = '' !== trim($search_query);
$search_placeholder = function_exists('aksrt_get_search_placeholder') ? aksrt_get_search_placeholder() : __('开启精彩搜索', 'aksrt');
$search_type = $search_state['type'];
$search_type_options = !empty($search_state['types']) && is_array($search_state['types']) ? $search_state['types'] : ['post' => __('文章', 'aksrt')];
$hot_keywords = function_exists('aksrt_get_search_hot_keywords') ? aksrt_get_search_hot_keywords() : [];
$filter_settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_post_filter_settings()
: ['enabled' => false, 'categories' => true, 'tags' => false, 'sort' => true];
$other_page_settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_other_page_settings()
: ['page_search_sidebar' => true];
$popular_categories = get_categories([
'taxonomy' => 'category',
'hide_empty' => true,
'number' => 4,
'orderby' => 'count',
'order' => 'DESC',
]);
$search_query = trim(wp_strip_all_tags(get_search_query()));
$search_type = function_exists('aksrt_get_search_form_type') ? aksrt_get_search_form_type() : 'post';
$search_types = function_exists('aksrt_get_search_type_options') ? aksrt_get_search_type_options() : ['post' => __('文章', 'aksrt')];
$search_category = isset($_REQUEST['trem']) ? absint(wp_unslash($_REQUEST['trem'])) : 0;
$search_user = isset($_REQUEST['user']) ? absint(wp_unslash($_REQUEST['user'])) : 0;
$paged = max(1, (int) get_query_var('paged'));
$history_value = $search_query . ($search_type !== '' ? '&type=' . $search_type : '');
$current_category = (int) ($search_state['category_id'] ?? 0);
$search_categories = is_array($search_state['categories'] ?? null) ? $search_state['categories'] : [];
$search_category_enabled = !empty($search_state['category_enabled']);
$current_orderby = sanitize_key((string) get_query_var('orderby'));
$current_order = strtoupper(sanitize_key((string) get_query_var('order')));
$current_sort = 'relevance';
if ($current_orderby === 'date' && $current_order === 'DESC') {
$current_sort = 'latest';
} elseif ($current_orderby === 'date' && $current_order === 'ASC') {
$current_sort = 'oldest';
} elseif ($current_orderby === 'comment_count') {
$current_sort = 'popular';
if ($search_query !== '' && function_exists('aksrt_save_history_search')) {
aksrt_save_history_search($history_value);
}
if ($current_category > 0 && $search_type === 'post') {
$filtered_query_args = [
's' => $search_query,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => (int) get_option('posts_per_page'),
'paged' => max(1, (int) get_query_var('paged')),
'cat' => $current_category,
'ignore_sticky_posts' => true,
];
if ($current_orderby !== '') {
$filtered_query_args['orderby'] = $current_orderby;
}
if ($current_order !== '') {
$filtered_query_args['order'] = $current_order;
}
$loop_query = new WP_Query($filtered_query_args);
}
$search_count = isset($loop_query->found_posts) ? (int) $loop_query->found_posts : 0;
$render_config = function_exists('aksrt_archive_get_render_config')
? aksrt_archive_get_render_config([
'context' => 'search',
'highlight_query' => $search_query,
])
: [
'context' => 'search',
'mode' => 'list',
'highlight_query' => $search_query,
];
$search_sort_options = [
'relevance' => [
'label' => __('综合', 'aksrt'),
'args' => ['orderby' => false, 'order' => false],
],
'latest' => [
'label' => __('最新', 'aksrt'),
'args' => ['orderby' => 'date', 'order' => 'desc'],
],
'oldest' => [
'label' => __('最早', 'aksrt'),
'args' => ['orderby' => 'date', 'order' => 'asc'],
],
'popular' => [
'label' => __('热门', 'aksrt'),
'args' => ['orderby' => 'comment_count', 'order' => 'desc'],
],
];
$has_sidebar = function_exists('aksrt_archive_has_sidebar')
? aksrt_archive_has_sidebar('search_sidebar', !empty($other_page_settings['page_search_sidebar']))
: (!empty($other_page_settings['page_search_sidebar']) && is_active_sidebar('search_sidebar'));
if (function_exists('aksrt_archive_open_shell')) {
aksrt_archive_open_shell([
'main_class' => 'site-main container',
'has_sidebar' => $has_sidebar,
'top_fluid' => ['search_top_fluid'],
'page_kind' => 'search',
$user_query = null;
if ($search_type === 'user' && $search_query !== '') {
$user_page = max(1, isset($_REQUEST['user_paged']) ? absint(wp_unslash($_REQUEST['user_paged'])) : 1);
$orderby = isset($_REQUEST['orderby']) ? sanitize_key(wp_unslash($_REQUEST['orderby'])) : 'name';
$orderby = in_array($orderby, ['name', 'registered'], true) ? $orderby : 'name';
$user_query = new WP_User_Query([
'search' => '*' . $search_query . '*',
'search_columns' => ['user_email', 'user_nicename', 'display_name', 'user_login'],
'count_total' => true,
'number' => 12,
'paged' => $user_page,
'orderby' => $orderby === 'registered' ? 'user_registered' : 'display_name',
'order' => 'DESC',
]);
}
$search_total = $user_query instanceof WP_User_Query ? (int) $user_query->get_total() : (int) $wp_query->found_posts;
if ($search_query !== '' && $search_total > 0 && $paged <= 1 && function_exists('aksrt_update_search_keywords')) {
aksrt_update_search_keywords($history_value);
}
get_header();
if (is_active_sidebar('search_top_fluid')) {
echo '<div class="fluid-widget-wrap">';
dynamic_sidebar('search_top_fluid');
echo '</div>';
}
?>
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['search_top_content']); } elseif (is_active_sidebar('search_top_content')) { dynamic_sidebar('search_top_content'); } ?>
<main class="container">
<div class="content-wrap">
<div class="content-layout">
<?php if (is_active_sidebar('search_top_content')) dynamic_sidebar('search_top_content'); ?>
<?php
$search_args = [
'class' => 'main-search page-search-box',
'show_posts' => false,
'in_cat' => $search_category,
'in_type' => $search_type,
'in_user' => $search_user,
's' => $search_query,
];
echo '<div class="zib-widget"' . ($paged < 2 ? ' win-ajax-replace="search"' : '') . '>';
if (function_exists('aksrt_get_main_search')) aksrt_get_main_search($search_args, true);
echo '</div>';
<div class="content-main content-main--search">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<?php
$search_title = $has_search_query
? sprintf(esc_html__('搜索“%s”', 'aksrt'), esc_html($search_query))
: esc_html__('搜索内容', 'aksrt');
$search_desc = $has_search_query
? sprintf(esc_html__('共找到 %1$d 条与 “%2$s” 相关的内容。', 'aksrt'), $search_count, esc_html($search_query))
: esc_html__('输入关键词,快速查找文章、教程和站内内容。', 'aksrt');
ob_start();
if (function_exists('aksrt_render_admin_quick_link')) {
aksrt_render_admin_quick_link('page-display/other', __('搜索页设置', 'aksrt'));
}
$admin_link = trim((string) ob_get_clean());
get_template_part('templates/parts/page-header', null, [
'eyebrow' => __('站内搜索', 'aksrt'),
'title' => $search_title,
'desc' => $search_desc,
'extra' => $admin_link,
]);
$base_url = add_query_arg(['s' => $search_query, 'user' => $search_user], home_url('/'));
$tab_nav = '';
foreach ($search_types as $key => $label) {
if ($search_type === $key) {
$tab_nav .= '<li class="active"><a class="focus-color" href="javascript:;">' . esc_html($label) . '</a></li>';
} else {
$tab_nav .= '<li><a ajax-replace="true" route="1" class="ajax-next" href="' . esc_url(add_query_arg('type', $key, $base_url)) . '">' . esc_html($label) . '</a></li>';
}
}
$tab_nav = '<div class="list-inline scroll-x mini-scrollbar tab-nav-theme">' . $tab_nav . '</div>';
$description = sprintf(
__('搜索 %1$s ,共找到 %2$s 个%3$s', 'aksrt'),
'<b class="search-key focus-color">' . esc_html($search_query) . '</b>',
'<b class="focus-color">' . esc_html(number_format_i18n($search_total)) . '</b>',
esc_html($search_types[$search_type] ?? __('内容', 'aksrt'))
);
?>
<div class="ajaxpager search-page-ajaxpager">
<div class="ajax-item-header type-<?php echo esc_attr($search_type); ?>">
<div class="search-desc-text mb10 mt10 muted-2-color"><?php echo wp_kses_post($description); ?></div>
<div class="search-tab-header zib-widget relative padding-h10"><div><?php echo $tab_nav; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div><div class="search-tab-filter"><?php echo function_exists('aksrt_get_search_tab_nav_filter') ? aksrt_get_search_tab_nav_filter($search_type) : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div></div>
</div>
<?php if ($search_query === '') : ?>
<div class="zib-widget search-content"><div class="text-center muted-2-color padding-20"><?php esc_html_e('请输入搜索关键词', 'aksrt'); ?></div></div>
<?php elseif ($user_query instanceof WP_User_Query && $user_query->get_results()) : ?>
<div class="zib-widget">
<?php foreach ($user_query->get_results() as $result_user) :
$user_id = (int) $result_user->ID;
$user_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user_id) : get_author_posts_url($user_id);
?>
<section class="content-stream content-stream--search content-stream--archive" data-page-kind="search" data-render-mode="<?php echo esc_attr((string) $render_config['mode']); ?>" data-list-type="<?php echo esc_attr((string) $render_config['list_type']); ?>">
<form role="search" method="get" class="search-hero-form search-page-form" action="<?php echo esc_url(home_url('/')); ?>" data-aksrt-search-form="search-page" data-default-search-type="<?php echo esc_attr($search_type); ?>" data-default-category="<?php echo esc_attr((string) $current_category); ?>">
<input type="hidden" name="aksrt_search_type" value="<?php echo esc_attr($search_type); ?>">
<?php if ($search_category_enabled) : ?>
<input type="hidden" name="aksrt_category" value="<?php echo esc_attr((string) $current_category); ?>">
<?php endif; ?>
<span class="search-icon search-page-form__icon" aria-hidden="true">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
</span>
<label class="screen-reader-text" for="search-page-input"><?php esc_html_e('搜索', 'aksrt'); ?></label>
<input type="search" id="search-page-input" name="s" value="<?php echo esc_attr($search_query); ?>" placeholder="<?php echo esc_attr($search_placeholder); ?>" autocomplete="off">
<button type="button" class="clear-search search-page-form__clear" id="search-clear-btn" aria-label="<?php esc_attr_e('清空搜索内容', 'aksrt'); ?>"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
<button type="submit" class="search-page-form__submit"><?php esc_html_e('搜索', 'aksrt'); ?></button>
</form>
<?php if (!empty($search_type_options)) : ?>
<div class="search-page-form__meta">
<div class="search-page-form__types" aria-label="<?php esc_attr_e('搜索类型', 'aksrt'); ?>">
<?php foreach ($search_type_options as $type_key => $type_label) : ?>
<button type="button" class="search-page-form__type<?php echo $search_type === $type_key ? ' is-active' : ''; ?>" data-search-type="<?php echo esc_attr($type_key); ?>"><?php echo esc_html($type_label); ?></button>
<?php endforeach; ?>
</div>
<?php if ($search_category_enabled && !empty($search_categories)) : ?>
<div class="search-page-form__category-wrap">
<label class="screen-reader-text" for="search-page-category"><?php esc_html_e('筛选分类', 'aksrt'); ?></label>
<select class="search-page-form__category" id="search-page-category" data-search-category-select>
<option value="0"><?php esc_html_e('全部分类', 'aksrt'); ?></option>
<?php foreach ($search_categories as $search_category) : ?>
<option value="<?php echo esc_attr((string) $search_category->term_id); ?>"<?php selected($current_category, (int) $search_category->term_id); ?>><?php echo esc_html($search_category->name); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php aksrt_render_search_hot_keywords($hot_keywords, 'aksrt-search-hot-keywords'); ?>
<?php if (!empty($filter_settings['enabled'])) : ?>
<div class="search-page-filters" aria-label="<?php esc_attr_e('搜索筛选', 'aksrt'); ?>">
<?php if (!empty($search_type_options)) : ?>
<div class="search-page-filters__group">
<span class="search-page-filters__label"><?php esc_html_e('类型', 'aksrt'); ?></span>
<div class="search-page-filters__chips">
<?php foreach ($search_type_options as $type_key => $type_label) : ?>
<?php
$type_args = [
'aksrt_search_type' => $type_key,
'paged' => false,
];
if ($type_key !== 'post') {
$type_args['aksrt_category'] = false;
} elseif ($search_category_enabled && $current_category > 0) {
$type_args['aksrt_category'] = $current_category;
}
?>
<a class="search-page-filters__chip<?php echo $search_type === $type_key ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg($type_args)); ?>">
<?php echo esc_html($type_label); ?>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php if ($search_category_enabled && !empty($search_categories)) : ?>
<div class="search-page-filters__group">
<span class="search-page-filters__label"><?php esc_html_e('分类', 'aksrt'); ?></span>
<div class="search-page-filters__select-wrap">
<select class="search-page-filters__select" id="search-category-filter" aria-label="<?php esc_attr_e('选择分类', 'aksrt'); ?>"<?php echo $search_type !== 'post' ? ' disabled' : ''; ?>>
<option value=""><?php esc_html_e('全部分类', 'aksrt'); ?></option>
<?php foreach ($search_categories as $cat) : ?>
<?php $cat_count = isset($cat->count) ? (int) $cat->count : 0; ?>
<option value="<?php echo esc_attr((string) $cat->term_id); ?>"<?php selected($current_category, (int) $cat->term_id); ?>>
<?php echo esc_html($cat->name); ?>
<?php if ($cat_count > 0) : ?>(<?php echo esc_html((string) $cat_count); ?>)<?php endif; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<?php endif; ?>
<?php if (!empty($filter_settings['sort'])) : ?>
<div class="search-page-filters__group">
<span class="search-page-filters__label"><?php esc_html_e('排序', 'aksrt'); ?></span>
<div class="search-page-filters__chips">
<?php foreach ($search_sort_options as $sort_key => $sort_option) : ?>
<?php
$sort_args = [
'orderby' => $sort_option['args']['orderby'],
'order' => $sort_option['args']['order'],
'paged' => false,
];
if ($search_type !== 'post') {
$sort_args['aksrt_category'] = false;
} elseif ($search_category_enabled && $current_category > 0) {
$sort_args['aksrt_category'] = $current_category;
}
$sort_url = add_query_arg(array_filter($sort_args, static function ($value): bool {
return false !== $value;
}));
if ($sort_key === 'relevance') {
$sort_url = remove_query_arg(['orderby', 'order', 'paged'], $sort_url);
if ($search_type !== 'post') {
$sort_url = remove_query_arg('aksrt_category', $sort_url);
} elseif ($search_category_enabled && $current_category > 0) {
$sort_url = add_query_arg('aksrt_category', $current_category, $sort_url);
}
}
?>
<a class="search-page-filters__chip<?php echo $current_sort === $sort_key ? ' is-active' : ''; ?>" href="<?php echo esc_url($sort_url); ?>">
<?php echo esc_html($sort_option['label']); ?>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="search-page-toolbar" aria-label="<?php esc_attr_e('搜索状态', 'aksrt'); ?>">
<span class="search-page-toolbar__count"><?php printf(esc_html(_n('%d 条结果', '%d 条结果', $search_count, 'aksrt')), $search_count); ?></span>
<?php if ($has_search_query) : ?>
<a class="search-page-toolbar__reset" href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('清除条件', 'aksrt'); ?></a>
<?php endif; ?>
</div>
<?php if ($loop_query->have_posts()) : ?>
<?php aksrt_render_post_list(array_merge($render_config, ['wrapper_class' => 'content-stream__list']), $loop_query); ?>
<div class="content-stream__footer">
<?php aksrt_render_pagination($loop_query, ['query_context' => 'search', 'render_config' => $render_config]); ?>
</div>
<?php else : ?>
<div class="no-results search-page-empty content-stream__empty">
<p class="search-page-empty__icon" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg></p>
<h2><?php esc_html_e('未找到相关内容', 'aksrt'); ?></h2>
<p class="search-page-empty__text"><?php esc_html_e('换一个更具体的关键词,或者从常用入口继续浏览。', 'aksrt'); ?></p>
<div class="search-page-empty__tips">
<span><?php esc_html_e('建议:', 'aksrt'); ?></span>
<span><?php esc_html_e('减少修饰词', 'aksrt'); ?></span>
<span><?php esc_html_e('尝试文章标题中的核心名词', 'aksrt'); ?></span>
<span><?php esc_html_e('改用更短的关键词', 'aksrt'); ?></span>
</div>
<div class="search-page-empty__actions">
<a class="btn-outline" href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('返回首页', 'aksrt'); ?></a>
<?php if (!empty($popular_categories)) : ?>
<?php foreach ($popular_categories as $category) : ?>
<a class="search-page-empty__chip" href="<?php echo esc_url(get_category_link($category->term_id)); ?>"><?php echo esc_html($category->name); ?></a>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</section>
<a class="author-minicard radius8 flex ac ajax-item" href="<?php echo esc_url($user_url); ?>">
<span class="avatar-img mr10"><?php echo function_exists('aksrt_get_avatar_html') ? aksrt_get_avatar_html($user_id, 48) : get_avatar($user_id, 48); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
<span class="flex1"><b><?php echo esc_html($result_user->display_name); ?></b><span class="muted-2-color em09 block text-ellipsis"><?php echo esc_html(wp_trim_words((string) $result_user->description, 16)); ?></span></span>
</a>
<?php endforeach; ?>
</div>
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['search_bottom_content']); } elseif (is_active_sidebar('search_bottom_content')) { dynamic_sidebar('search_bottom_content'); } ?>
<?php
$user_pages = (int) ceil($search_total / 12);
if ($user_pages > 1) {
echo '<div class="text-center theme-pagination ajax-pag">' . paginate_links(['base' => esc_url_raw(add_query_arg('user_paged', '%#%')), 'current' => $user_page, 'total' => $user_pages, 'prev_text' => '<i class="fa fas fa-angle-left"></i>', 'next_text' => '<i class="fa fas fa-angle-right"></i>']) . '</div>';
}
?>
<?php elseif ($search_type === 'post' && $wp_query->have_posts()) : ?>
<div class="posts-row mtn6">
<?php
$config = function_exists('aksrt_archive_get_render_config') ? aksrt_archive_get_render_config(['context' => 'search', 'highlight_query' => $search_query]) : ['context' => 'search', 'mode' => 'list'];
aksrt_render_post_list(array_merge($config, ['wrapper_class' => '']), $wp_query);
?>
</div>
<?php aksrt_render_pagination($wp_query, ['query_context' => 'search', 'render_config' => $config]); ?>
<?php else : ?>
<div class="zib-widget search-content"><div class="text-center muted-2-color padding-20"><?php esc_html_e('未找到相关内容', 'aksrt'); ?></div></div>
<?php endif; ?>
<div class="post_ajax_loader search-loader" style="display:none"><div class="mb20"><div class="text-center muted-2-color mt20"><i class="loading mr10"></i><?php esc_html_e('加载中...', 'aksrt'); ?></div></div></div>
</div>
<?php if (is_active_sidebar('search_bottom_content')) dynamic_sidebar('search_bottom_content'); ?>
</div>
</div>
<?php get_sidebar(); ?>
</main>
<?php
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell([
'has_sidebar' => $has_sidebar,
'bottom_fluid' => ['search_bottom_fluid'],
]);
if (is_active_sidebar('search_bottom_fluid')) {
echo '<div class="fluid-widget-wrap">';
dynamic_sidebar('search_bottom_fluid');
echo '</div>';
}
get_footer();