Merge pull request '统一 archive/category/tag/search 主内容流壳层' (#23) from worktree-bg-unified-single-home-mainline into main
Reviewed-on: CYL/wordpress-theme-aksrt#23
This commit is contained in:
+51
-71
@@ -11,47 +11,19 @@ get_header();
|
||||
|
||||
global $wp_query;
|
||||
|
||||
$list_settings = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::get_post_list_style_settings()
|
||||
: ['render_mode' => 'card', 'card_style' => 'standard'];
|
||||
$render_config = [
|
||||
'context' => 'archive',
|
||||
'mode' => (string) ($list_settings['render_mode'] ?? 'card'),
|
||||
'card_style' => (string) ($list_settings['card_style'] ?? 'standard'),
|
||||
];
|
||||
$render_config = function_exists('aksrt_archive_get_render_config')
|
||||
? aksrt_archive_get_render_config(['context' => 'archive'])
|
||||
: ['context' => 'archive', 'mode' => 'card', 'card_style' => 'standard'];
|
||||
$has_sidebar = function_exists('aksrt_archive_has_sidebar')
|
||||
? aksrt_archive_has_sidebar()
|
||||
: (function_exists('aksrt_is_show_sidebar') ? aksrt_is_show_sidebar() : false);
|
||||
|
||||
// Per-category card mode override: if visiting a category in card_cat_ids, force card mode
|
||||
if (is_category() && !empty($list_settings['card_cat_ids'])) {
|
||||
$current_cat_id = (int) get_queried_object_id();
|
||||
if (in_array($current_cat_id, $list_settings['card_cat_ids'], true)) {
|
||||
$render_config['mode'] = 'card';
|
||||
}
|
||||
}
|
||||
|
||||
// Per-category multi-thumb override
|
||||
if (is_category() && class_exists('AKSRT_Settings')) {
|
||||
$thumb_settings = AKSRT_Settings::get_post_thumb_settings();
|
||||
if (!empty($thumb_settings['mult_thumb_cat_ids'])) {
|
||||
$current_cat_id = (int) get_queried_object_id();
|
||||
if (in_array($current_cat_id, $thumb_settings['mult_thumb_cat_ids'], true)) {
|
||||
$render_config['multi_thumb_enabled'] = true;
|
||||
$render_config['multi_thumb_limit'] = (int) ($thumb_settings['multi_count'] ?? 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$has_sidebar = function_exists('aksrt_is_show_sidebar') ? aksrt_is_show_sidebar() : false;
|
||||
$archive_description = trim(strip_tags((string) get_the_archive_description()));
|
||||
$archive_description = trim(wp_strip_all_tags((string) get_the_archive_description()));
|
||||
$archive_summary = '';
|
||||
|
||||
if (is_author()) {
|
||||
$author = get_queried_object();
|
||||
if ($author instanceof WP_User) {
|
||||
$archive_summary = sprintf(
|
||||
/* translators: %s: author display name */
|
||||
__('作者:%s', 'aksrt'),
|
||||
$author->display_name
|
||||
);
|
||||
$archive_summary = sprintf(__('作者:%s', 'aksrt'), $author->display_name);
|
||||
}
|
||||
} elseif ($archive_description !== '') {
|
||||
$archive_summary = $archive_description;
|
||||
@@ -61,43 +33,51 @@ if (is_author()) {
|
||||
(int) $wp_query->found_posts
|
||||
);
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_archive_open_shell')) {
|
||||
aksrt_archive_open_shell([
|
||||
'main_class' => 'site-main content-shell content-shell--stream',
|
||||
'has_sidebar' => $has_sidebar,
|
||||
'page_kind' => 'archive',
|
||||
]);
|
||||
} else {
|
||||
echo '<main id="main-content" class="site-main content-shell content-shell--stream" tabindex="-1"><div class="content-wrap"><div class="content-layout' . ($has_sidebar ? '' : ' content-layout--no-sidebar') . '"><div class="content-layout__primary">';
|
||||
}
|
||||
?>
|
||||
<div class="content-main content-main--archive">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<main id="main-content" class="site-main content-shell content-shell--stream" tabindex="-1">
|
||||
<div class="content-layout<?php echo $has_sidebar ? '' : ' content-layout--no-sidebar'; ?>">
|
||||
<div class="content-layout__primary">
|
||||
<div class="content-main content-main--archive">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php
|
||||
$admin_link = function_exists('aksrt_render_admin_quick_link') ? aksrt_render_admin_quick_link('post-list/list', __('列表样式设置', 'aksrt')) : '';
|
||||
set_query_var('aksrt_ph_eyebrow', __('内容归档', 'aksrt'));
|
||||
set_query_var('aksrt_ph_title', get_the_archive_title());
|
||||
set_query_var('aksrt_ph_desc', $archive_summary);
|
||||
set_query_var('aksrt_ph_extra', $admin_link);
|
||||
get_template_part('templates/parts/page-header');
|
||||
?>
|
||||
|
||||
<section class="content-stream content-stream--archive" data-page-kind="archive" data-render-mode="<?php echo esc_attr((string) $render_config['mode']); ?>" data-card-style="<?php echo esc_attr((string) $render_config['card_style']); ?>">
|
||||
<?php if (have_posts()) : ?>
|
||||
<?php aksrt_render_post_list(null, array_merge($render_config, ['wrapper_class' => 'content-stream__list'])); ?>
|
||||
<div class="content-stream__footer">
|
||||
<?php aksrt_render_pagination(null, ['query_context' => 'archive', 'render_config' => $render_config]); ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="no-results content-stream__empty">
|
||||
<p><?php esc_html_e('暂无文章', 'aksrt'); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($has_sidebar) : ?>
|
||||
<?php get_sidebar(); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</main>
|
||||
<?php
|
||||
ob_start();
|
||||
if (function_exists('aksrt_render_admin_quick_link')) {
|
||||
aksrt_render_admin_quick_link('post-list/list', __('列表样式设置', 'aksrt'));
|
||||
}
|
||||
$admin_link = trim((string) ob_get_clean());
|
||||
set_query_var('aksrt_ph_eyebrow', __('内容归档', 'aksrt'));
|
||||
set_query_var('aksrt_ph_title', get_the_archive_title());
|
||||
set_query_var('aksrt_ph_desc', $archive_summary);
|
||||
set_query_var('aksrt_ph_extra', $admin_link);
|
||||
get_template_part('templates/parts/page-header');
|
||||
?>
|
||||
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_render_stream')) {
|
||||
aksrt_archive_render_stream(null, $render_config, [
|
||||
'page_kind' => 'archive',
|
||||
'query_context' => 'archive',
|
||||
'stream_class' => 'content-stream--archive',
|
||||
'empty_text' => __('暂无文章', 'aksrt'),
|
||||
]);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_close_shell')) {
|
||||
aksrt_archive_close_shell(['has_sidebar' => $has_sidebar]);
|
||||
} else {
|
||||
echo '</div>';
|
||||
if ($has_sidebar) { get_sidebar(); }
|
||||
echo '</div></div></main>';
|
||||
}
|
||||
|
||||
get_footer();
|
||||
|
||||
+143
-172
@@ -11,22 +11,22 @@ get_header();
|
||||
|
||||
$term = get_queried_object();
|
||||
if (class_exists('AKSRT_Docs_Presenter')) {
|
||||
$docs_presenter = AKSRT_Docs_Presenter::get_instance();
|
||||
if ($term instanceof WP_Term && $term->taxonomy === 'category') {
|
||||
$doc_candidates = get_posts([
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => '_aksrt_doc_category',
|
||||
'meta_value' => (string) $term->term_id,
|
||||
'fields' => 'ids',
|
||||
]);
|
||||
if (!empty($doc_candidates)) {
|
||||
get_template_part('templates/pages/page-documentnav');
|
||||
get_footer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
$docs_presenter = AKSRT_Docs_Presenter::get_instance();
|
||||
if ($term instanceof WP_Term && $term->taxonomy === 'category') {
|
||||
$doc_candidates = get_posts([
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => '_aksrt_doc_category',
|
||||
'meta_value' => (string) $term->term_id,
|
||||
'fields' => 'ids',
|
||||
]);
|
||||
if (!empty($doc_candidates)) {
|
||||
get_template_part('templates/pages/page-documentnav');
|
||||
get_footer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$term instanceof WP_Term) {
|
||||
get_footer();
|
||||
@@ -44,10 +44,12 @@ $archive_settings = class_exists('AKSRT_Term_Meta')
|
||||
'filter_bar' => true,
|
||||
'cover_url' => '',
|
||||
'description' => (string) $term->description,
|
||||
'card_style' => 'standard',
|
||||
];
|
||||
|
||||
$sidebar_id = is_active_sidebar('cat_sidebar') ? 'cat_sidebar' : 'sidebar-blog';
|
||||
$has_sidebar = !empty($archive_settings['show_sidebar']) && is_active_sidebar($sidebar_id);
|
||||
$has_sidebar = function_exists('aksrt_archive_has_sidebar')
|
||||
? aksrt_archive_has_sidebar('cat_sidebar', !empty($archive_settings['show_sidebar']))
|
||||
: (!empty($archive_settings['show_sidebar']) && (is_active_sidebar('cat_sidebar') || is_active_sidebar('sidebar-blog')));
|
||||
$description = !empty($archive_settings['show_desc']) ? wp_kses_post((string) $archive_settings['description']) : '';
|
||||
$header_style = (string) $archive_settings['header_style'];
|
||||
$layout_mode = (string) $archive_settings['layout_mode'];
|
||||
@@ -63,37 +65,29 @@ $cat_filter_config = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::get_filter_config_for_category((int) $term->term_id)
|
||||
: ['dimensions' => [], 'show_cat' => true, 'show_tag' => false, 'show_topics' => false, 'show_orderby' => true];
|
||||
$custom_dimensions = $cat_filter_config['dimensions'];
|
||||
$current_orderby = sanitize_key((string) get_query_var('orderby'));
|
||||
$current_order = strtoupper(sanitize_key((string) get_query_var('order')));
|
||||
$current_sort = 'latest';
|
||||
|
||||
if ($current_orderby === 'date' && $current_order === 'ASC') {
|
||||
$current_sort = 'oldest';
|
||||
} elseif ($current_orderby === 'comment_count') {
|
||||
$current_sort = 'popular';
|
||||
}
|
||||
|
||||
$render_config = [
|
||||
'context' => 'category',
|
||||
'mode' => $layout_mode,
|
||||
'card_style' => $card_style,
|
||||
];
|
||||
$sort_links = [
|
||||
'latest' => remove_query_arg(['orderby', 'order', 'paged']),
|
||||
'oldest' => add_query_arg(['orderby' => 'date', 'order' => 'asc', 'paged' => false]),
|
||||
'popular' => add_query_arg(['orderby' => 'comment_count', 'order' => 'desc', 'paged' => false]),
|
||||
];
|
||||
$sort_state = function_exists('aksrt_archive_get_sort_state') ? aksrt_archive_get_sort_state() : ['current' => 'latest', 'links' => []];
|
||||
$current_sort = $sort_state['current'];
|
||||
$sort_links = $sort_state['links'];
|
||||
$render_config = function_exists('aksrt_archive_get_render_config')
|
||||
? aksrt_archive_get_render_config([
|
||||
'context' => 'category',
|
||||
'mode' => $layout_mode,
|
||||
'card_style' => $card_style,
|
||||
])
|
||||
: [
|
||||
'context' => 'category',
|
||||
'mode' => $layout_mode,
|
||||
'card_style' => $card_style,
|
||||
];
|
||||
|
||||
$filter_terms = [];
|
||||
$filter_all_url = get_category_link($term->term_id);
|
||||
if (!empty($archive_settings['filter_bar'])) {
|
||||
$filter_parent = $term->term_id;
|
||||
$filter_terms = get_terms([
|
||||
'taxonomy' => 'category',
|
||||
'hide_empty' => true,
|
||||
'parent' => $filter_parent,
|
||||
'parent' => $term->term_id,
|
||||
]);
|
||||
|
||||
if (empty($filter_terms) && !empty($term->parent)) {
|
||||
$filter_all_url = get_category_link((int) $term->parent);
|
||||
$filter_terms = get_terms([
|
||||
@@ -102,7 +96,6 @@ if (!empty($archive_settings['filter_bar'])) {
|
||||
'parent' => (int) $term->parent,
|
||||
]);
|
||||
}
|
||||
|
||||
if (is_wp_error($filter_terms)) {
|
||||
$filter_terms = [];
|
||||
}
|
||||
@@ -126,145 +119,123 @@ if ($ajax_filter && !empty($filter_settings['cat_show_tag'])) {
|
||||
$tag_filter_terms = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_archive_open_shell')) {
|
||||
aksrt_archive_open_shell([
|
||||
'main_class' => 'site-main container content-shell content-shell--stream',
|
||||
'has_sidebar' => $has_sidebar,
|
||||
'top_fluid' => ['cat_top_fluid'],
|
||||
'page_kind' => 'category',
|
||||
]);
|
||||
}
|
||||
?>
|
||||
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['cat_top_content']); } elseif (is_active_sidebar('cat_top_content')) { dynamic_sidebar('cat_top_content'); } ?>
|
||||
|
||||
<main id="main-content" class="site-main container" tabindex="-1">
|
||||
<?php
|
||||
if (is_active_sidebar('cat_top_fluid')) {
|
||||
echo '<div class="fluid-widget-wrap">';
|
||||
dynamic_sidebar('cat_top_fluid');
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
<div class="content-wrap">
|
||||
<div class="content-layout<?php echo $has_sidebar ? '' : ' content-layout--no-sidebar'; ?>">
|
||||
<div class="content-layout__primary">
|
||||
<div class="content-main content-main--archive content-main--category">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php if (is_active_sidebar('cat_top_content')) { dynamic_sidebar('cat_top_content'); } ?>
|
||||
|
||||
<div class="content-main content-main--archive content-main--category">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php if ($header_style !== 'none') : ?>
|
||||
<header class="page-header term-page-header term-page-header--<?php echo esc_attr($header_style); ?><?php echo (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') ? ' has-cover-bg' : ''; ?>">
|
||||
<?php if (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') : ?>
|
||||
<div class="term-page-header__cover-bg" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')">
|
||||
<div class="term-page-header__cover-overlay"></div>
|
||||
<?php if ($header_style !== 'none') : ?>
|
||||
<header class="page-header term-page-header term-page-header--<?php echo esc_attr($header_style); ?><?php echo (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') ? ' has-cover-bg' : ''; ?>">
|
||||
<?php if (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') : ?>
|
||||
<div class="term-page-header__cover-bg" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')">
|
||||
<div class="term-page-header__cover-overlay"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="term-page-header__body<?php echo $header_style === 'cover' ? ' term-page-header__body--overlay' : ''; ?>">
|
||||
<div>
|
||||
<p class="term-page-header__eyebrow"><?php esc_html_e('分类归档', 'aksrt'); ?></p>
|
||||
<h1 class="entry-title"><?php single_cat_title(); ?></h1>
|
||||
<?php if ($description !== '') : ?>
|
||||
<p class="term-page-header__desc"><?php echo $description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/category', __('分类页设置', 'aksrt')); } ?>
|
||||
</div>
|
||||
<?php if (!empty($archive_settings['show_cover']) && $header_style !== 'cover') : ?>
|
||||
<div class="term-page-header__cover" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')"></div>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
<div class="term-page-header__body<?php echo $header_style === 'cover' ? ' term-page-header__body--overlay' : ''; ?>">
|
||||
<div>
|
||||
<p class="term-page-header__eyebrow"><?php esc_html_e('分类归档', 'aksrt'); ?></p>
|
||||
<h1 class="entry-title"><?php single_cat_title(); ?></h1>
|
||||
<?php if ($description !== '') : ?>
|
||||
<p class="term-page-header__desc"><?php echo $description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($archive_settings['filter_bar']) && (!empty($filter_terms) || !empty($tag_filter_terms) || !empty($custom_dimensions))) : ?>
|
||||
<div class="archive-filter-bar<?php echo $ajax_filter ? ' archive-filter-bar--ajax' : ''; ?>" aria-label="<?php esc_attr_e('分类筛选', 'aksrt'); ?>"<?php if ($ajax_filter) : ?> data-ajax-archive="category" data-term-id="<?php echo (int) $term->term_id; ?>" data-query-context="archive" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php endif; ?>>
|
||||
<?php if (!empty($filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('分类导航', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo (empty($term->parent) && $current_filter_cat === '') ? ' is-active' : ''; ?>" href="<?php echo esc_url($filter_all_url); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="0"<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($filter_terms as $filter_term) : ?>
|
||||
<?php $is_current = ((int) $filter_term->term_id === (int) $term->term_id) || ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $filter_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current ? ' is-active' : ''; ?>" href="<?php echo esc_url(get_term_link($filter_term)); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="<?php echo (int) $filter_term->term_id; ?>"<?php endif; ?>><?php echo esc_html($filter_term->name); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/category', __('分类页设置', 'aksrt')); } ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($tag_filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main archive-filter-bar__main--tags">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('标签', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo $current_filter_tag === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url(remove_query_arg(['aksrt_filter_tag'])); ?>"<?php if ($ajax_filter) : ?> data-filter-tag=""<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($tag_filter_terms as $tag_term) : ?>
|
||||
<?php $is_current_tag = ($current_filter_tag !== '' && (int) $current_filter_tag === (int) $tag_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_tag ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_filter_tag', (int) $tag_term->term_id)); ?>"<?php if ($ajax_filter) : ?> data-filter-tag="<?php echo (int) $tag_term->term_id; ?>"<?php endif; ?>><?php echo esc_html($tag_term->name); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="archive-filter-bar__meta">
|
||||
<?php printf(esc_html(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt')), (int) $term->count); ?>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($filter_settings['enabled']) && !empty($filter_settings['sort'])) : ?>
|
||||
<div class="archive-filter-bar__sort" aria-label="<?php esc_attr_e('排序方式', 'aksrt'); ?>">
|
||||
<?php foreach ($sort_links as $sort_key => $sort_url) : ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $current_sort === $sort_key ? ' is-active' : ''; ?>" href="<?php echo esc_url($sort_url); ?>"<?php if ($ajax_filter) : ?> data-filter-sort="<?php echo esc_attr($sort_key); ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($sort_key === 'oldest' ? __('最早', 'aksrt') : ($sort_key === 'popular' ? __('热门', 'aksrt') : __('最新', 'aksrt'))); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($custom_dimensions as $dim) : ?>
|
||||
<div class="archive-filter-bar__main archive-filter-bar__main--custom">
|
||||
<span class="archive-filter-bar__label"><?php echo esc_html($dim['name']); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<?php $cf_all_url = remove_query_arg('aksrt_cf_' . $dim['key']); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo ($current_cf_values[$dim['key']] ?? '') === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url($cf_all_url); ?>"<?php if ($ajax_filter) : ?> data-filter-cf="<?php echo esc_attr($dim['key']); ?>" data-filter-cf-val=""<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($dim['vals'] as $val) : ?>
|
||||
<?php $is_current_cf = ($current_cf_values[$dim['key']] ?? '') === $val['key']; ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_cf ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_cf_' . $dim['key'], $val['key'])); ?>"<?php if ($ajax_filter) : ?> data-filter-cf="<?php echo esc_attr($dim['key']); ?>" data-filter-cf-val="<?php echo esc_attr($val['key']); ?>"<?php endif; ?>><?php echo esc_html($val['name']); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if (!empty($archive_settings['show_cover']) && $header_style !== 'cover') : ?>
|
||||
<div class="term-page-header__cover" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')"></div>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($archive_settings['filter_bar']) && (!empty($filter_terms) || !empty($tag_filter_terms) || !empty($custom_dimensions))) : ?>
|
||||
<div class="archive-filter-bar<?php echo $ajax_filter ? ' archive-filter-bar--ajax' : ''; ?>" aria-label="<?php esc_attr_e('分类筛选', 'aksrt'); ?>"<?php if ($ajax_filter) : ?> data-ajax-archive="category" data-term-id="<?php echo (int) $term->term_id; ?>" data-query-context="archive" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php endif; ?>>
|
||||
<?php if (!empty($filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('分类导航', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo (empty($term->parent) && $current_filter_cat === '') ? ' is-active' : ''; ?>" href="<?php echo esc_url($filter_all_url); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="0"<?php endif; ?>>
|
||||
<?php esc_html_e('全部', 'aksrt'); ?>
|
||||
</a>
|
||||
<?php foreach ($filter_terms as $filter_term) : ?>
|
||||
<?php $is_current = ((int) $filter_term->term_id === (int) $term->term_id) || ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $filter_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current ? ' is-active' : ''; ?>" href="<?php echo esc_url(get_term_link($filter_term)); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="<?php echo (int) $filter_term->term_id; ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($filter_term->name); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_render_stream')) {
|
||||
aksrt_archive_render_stream(null, $render_config, [
|
||||
'page_kind' => 'category',
|
||||
'query_context' => 'archive',
|
||||
'stream_class' => 'archive__ajax-wrap content-stream--archive content-stream--category',
|
||||
'empty_text' => __('该分类下暂无文章', 'aksrt'),
|
||||
'ajax_enabled' => $ajax_filter,
|
||||
'show_loading' => $ajax_filter,
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['cat_bottom_content']); } elseif (is_active_sidebar('cat_bottom_content')) { dynamic_sidebar('cat_bottom_content'); } ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($tag_filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main archive-filter-bar__main--tags">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('标签', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo $current_filter_tag === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url(remove_query_arg(['aksrt_filter_tag'])); ?>"<?php if ($ajax_filter) : ?> data-filter-tag=""<?php endif; ?>>
|
||||
<?php esc_html_e('全部', 'aksrt'); ?>
|
||||
</a>
|
||||
<?php foreach ($tag_filter_terms as $tag_term) : ?>
|
||||
<?php $is_current_tag = ($current_filter_tag !== '' && (int) $current_filter_tag === (int) $tag_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_tag ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_filter_tag', (int) $tag_term->term_id)); ?>"<?php if ($ajax_filter) : ?> data-filter-tag="<?php echo (int) $tag_term->term_id; ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($tag_term->name); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="archive-filter-bar__meta">
|
||||
<?php printf(esc_html(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt')), (int) $term->count); ?>
|
||||
</div>
|
||||
<?php if (!empty($filter_settings['enabled']) && !empty($filter_settings['sort'])) : ?>
|
||||
<div class="archive-filter-bar__sort" aria-label="<?php esc_attr_e('排序方式', 'aksrt'); ?>">
|
||||
<?php foreach ($sort_links as $sort_key => $sort_url) : ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $current_sort === $sort_key ? ' is-active' : ''; ?>" href="<?php echo esc_url($sort_url); ?>"<?php if ($ajax_filter) : ?> data-filter-sort="<?php echo esc_attr($sort_key); ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($sort_key === 'oldest' ? __('最早', 'aksrt') : ($sort_key === 'popular' ? __('热门', 'aksrt') : __('最新', 'aksrt'))); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($custom_dimensions as $dim) : ?>
|
||||
<div class="archive-filter-bar__main archive-filter-bar__main--custom">
|
||||
<span class="archive-filter-bar__label"><?php echo esc_html($dim['name']); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<?php $cf_all_url = remove_query_arg('aksrt_cf_' . $dim['key']); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo ($current_cf_values[$dim['key']] ?? '') === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url($cf_all_url); ?>"<?php if ($ajax_filter) : ?> data-filter-cf="<?php echo esc_attr($dim['key']); ?>" data-filter-cf-val=""<?php endif; ?>>
|
||||
<?php esc_html_e('全部', 'aksrt'); ?>
|
||||
</a>
|
||||
<?php foreach ($dim['vals'] as $val) : ?>
|
||||
<?php $is_current_cf = ($current_cf_values[$dim['key']] ?? '') === $val['key']; ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_cf ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_cf_' . $dim['key'], $val['key'])); ?>"<?php if ($ajax_filter) : ?> data-filter-cf="<?php echo esc_attr($dim['key']); ?>" data-filter-cf-val="<?php echo esc_attr($val['key']); ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($val['name']); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="archive__ajax-wrap content-stream content-stream--archive content-stream--category<?php echo $ajax_filter ? ' is-ajax-enabled' : ''; ?>" data-page-kind="category" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php if ($ajax_filter) : ?> data-ajax-wrap data-query-context="archive"<?php endif; ?>>
|
||||
<div class="archive__ajax-loading" aria-hidden="true"><span class="archive__ajax-spinner"></span></div>
|
||||
<?php if (have_posts()) : ?>
|
||||
<?php aksrt_render_post_list(null, array_merge($render_config, ['wrapper_class' => 'content-stream__list'])); ?>
|
||||
<div class="content-stream__footer">
|
||||
<?php aksrt_render_pagination(null, ['query_context' => 'archive', 'render_config' => $render_config]); ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="no-results content-stream__empty">
|
||||
<p><?php esc_html_e('该分类下暂无文章', 'aksrt'); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (is_active_sidebar('cat_bottom_content')) { dynamic_sidebar('cat_bottom_content'); } ?>
|
||||
</div>
|
||||
|
||||
<?php if ($has_sidebar) : ?>
|
||||
<?php get_sidebar(); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (is_active_sidebar('cat_bottom_fluid')) {
|
||||
echo '<div class="fluid-widget-wrap">';
|
||||
dynamic_sidebar('cat_bottom_fluid');
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_close_shell')) {
|
||||
aksrt_archive_close_shell([
|
||||
'has_sidebar' => $has_sidebar,
|
||||
'bottom_fluid' => ['cat_bottom_fluid'],
|
||||
]);
|
||||
}
|
||||
|
||||
get_footer();
|
||||
|
||||
@@ -28,6 +28,7 @@ require_once AKSRT_DIR . '/inc/helpers/aksrt-frontend-tags.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-flow.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-homepage.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-single.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-archive.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-slider.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-vip.php';
|
||||
require_once AKSRT_DIR . '/inc/helpers/aksrt-i18n-switch.php';
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
/**
|
||||
* Shared archive / category / tag / search stream helpers.
|
||||
*
|
||||
* Keeps list pages on one content-stream contract instead of four hand-rolled shells.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_archive_get_list_style_settings')) :
|
||||
/**
|
||||
* Shared list style defaults for archive surfaces.
|
||||
*
|
||||
* @return array{render_mode:string,card_style:string,card_cat_ids:array<int,int>}
|
||||
*/
|
||||
function aksrt_archive_get_list_style_settings(): array {
|
||||
$settings = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::get_post_list_style_settings()
|
||||
: [];
|
||||
|
||||
return [
|
||||
'render_mode' => (string) ($settings['render_mode'] ?? 'card'),
|
||||
'card_style' => (string) ($settings['card_style'] ?? 'standard'),
|
||||
'card_cat_ids' => is_array($settings['card_cat_ids'] ?? null) ? array_map('intval', $settings['card_cat_ids']) : [],
|
||||
];
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_get_render_config')) :
|
||||
/**
|
||||
* Build render config for archive-like pages.
|
||||
*
|
||||
* @param array<string,mixed> $overrides Context/mode overrides.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
function aksrt_archive_get_render_config(array $overrides = []): array {
|
||||
$list = aksrt_archive_get_list_style_settings();
|
||||
$config = array_merge([
|
||||
'context' => 'archive',
|
||||
'mode' => $list['render_mode'],
|
||||
'card_style' => $list['card_style'],
|
||||
], $overrides);
|
||||
|
||||
if (is_category() && !empty($list['card_cat_ids'])) {
|
||||
$current_cat_id = (int) get_queried_object_id();
|
||||
if (in_array($current_cat_id, $list['card_cat_ids'], true)) {
|
||||
$config['mode'] = 'card';
|
||||
}
|
||||
}
|
||||
|
||||
if (is_category() && class_exists('AKSRT_Settings')) {
|
||||
$thumb_settings = AKSRT_Settings::get_post_thumb_settings();
|
||||
if (!empty($thumb_settings['mult_thumb_cat_ids'])) {
|
||||
$current_cat_id = (int) get_queried_object_id();
|
||||
if (in_array($current_cat_id, array_map('intval', (array) $thumb_settings['mult_thumb_cat_ids']), true)) {
|
||||
$config['multi_thumb_enabled'] = true;
|
||||
$config['multi_thumb_limit'] = (int) ($thumb_settings['multi_count'] ?? 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_get_sort_state')) :
|
||||
/**
|
||||
* Shared latest/oldest/popular sort state for term archives.
|
||||
*
|
||||
* @return array{current:string,links:array<string,string>}
|
||||
*/
|
||||
function aksrt_archive_get_sort_state(): array {
|
||||
$current_orderby = sanitize_key((string) get_query_var('orderby'));
|
||||
$current_order = strtoupper(sanitize_key((string) get_query_var('order')));
|
||||
$current = 'latest';
|
||||
|
||||
if ($current_orderby === 'date' && $current_order === 'ASC') {
|
||||
$current = 'oldest';
|
||||
} elseif ($current_orderby === 'comment_count') {
|
||||
$current = 'popular';
|
||||
}
|
||||
|
||||
return [
|
||||
'current' => $current,
|
||||
'links' => [
|
||||
'latest' => remove_query_arg(['orderby', 'order', 'paged']),
|
||||
'oldest' => add_query_arg(['orderby' => 'date', 'order' => 'asc', 'paged' => false]),
|
||||
'popular' => add_query_arg(['orderby' => 'comment_count', 'order' => 'desc', 'paged' => false]),
|
||||
],
|
||||
];
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_has_sidebar')) :
|
||||
/**
|
||||
* Resolve whether a stream page should show an aside.
|
||||
*
|
||||
* @param string $preferred Preferred sidebar id.
|
||||
* @param bool $enabled Page-level sidebar toggle.
|
||||
*/
|
||||
function aksrt_archive_has_sidebar(string $preferred = '', bool $enabled = true): bool {
|
||||
if (!$enabled || wp_is_mobile()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($preferred !== '' && is_active_sidebar($preferred)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_is_show_sidebar')) {
|
||||
return aksrt_is_show_sidebar();
|
||||
}
|
||||
|
||||
$fallback = function_exists('aksrt_resolve_sidebar_id') ? aksrt_resolve_sidebar_id() : 'sidebar-blog';
|
||||
return is_active_sidebar($fallback)
|
||||
|| is_active_sidebar('all_sidebar_top')
|
||||
|| is_active_sidebar('all_sidebar_bottom');
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_render_widget_zone')) :
|
||||
/**
|
||||
* Render stacked sidebars when active.
|
||||
*
|
||||
* @param string[] $sidebar_ids Sidebar ids.
|
||||
* @param string $wrapper_class Wrapper class.
|
||||
*/
|
||||
function aksrt_archive_render_widget_zone(array $sidebar_ids, string $wrapper_class = ''): void {
|
||||
$active = [];
|
||||
foreach ($sidebar_ids as $sidebar_id) {
|
||||
if (is_active_sidebar($sidebar_id)) {
|
||||
$active[] = $sidebar_id;
|
||||
}
|
||||
}
|
||||
if (empty($active)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($wrapper_class !== '') {
|
||||
echo '<div class="' . esc_attr($wrapper_class) . '">';
|
||||
}
|
||||
foreach ($active as $sidebar_id) {
|
||||
dynamic_sidebar($sidebar_id);
|
||||
}
|
||||
if ($wrapper_class !== '') {
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_render_stream')) :
|
||||
/**
|
||||
* Shared list + pagination + empty state for archive surfaces.
|
||||
*
|
||||
* @param WP_Query|null $query Query or null for main loop.
|
||||
* @param array<string,mixed> $render_config Renderer config.
|
||||
* @param array<string,mixed> $args Stream args.
|
||||
*/
|
||||
function aksrt_archive_render_stream(?WP_Query $query, array $render_config, array $args = []): void {
|
||||
$args = wp_parse_args($args, [
|
||||
'page_kind' => 'archive',
|
||||
'query_context' => 'archive',
|
||||
'empty_text' => __('暂无文章', 'aksrt'),
|
||||
'stream_class' => '',
|
||||
'ajax_enabled' => false,
|
||||
'ajax_attrs' => '',
|
||||
'show_loading' => false,
|
||||
]);
|
||||
|
||||
$classes = [
|
||||
'content-stream',
|
||||
'content-stream--' . sanitize_html_class((string) $args['page_kind']),
|
||||
];
|
||||
if (!empty($args['stream_class'])) {
|
||||
foreach (preg_split('/\s+/', trim((string) $args['stream_class'])) ?: [] as $class) {
|
||||
$class = sanitize_html_class($class);
|
||||
if ($class !== '') {
|
||||
$classes[] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($args['ajax_enabled'])) {
|
||||
$classes[] = 'is-ajax-enabled';
|
||||
}
|
||||
|
||||
$mode = (string) ($render_config['mode'] ?? 'card');
|
||||
$card_style = (string) ($render_config['card_style'] ?? 'standard');
|
||||
$has_posts = $query instanceof WP_Query ? $query->have_posts() : have_posts();
|
||||
?>
|
||||
<div
|
||||
class="<?php echo esc_attr(implode(' ', array_unique($classes))); ?>"
|
||||
data-page-kind="<?php echo esc_attr((string) $args['page_kind']); ?>"
|
||||
data-render-mode="<?php echo esc_attr($mode); ?>"
|
||||
data-card-style="<?php echo esc_attr($card_style); ?>"
|
||||
<?php if (!empty($args['ajax_enabled'])) : ?>
|
||||
data-ajax-wrap
|
||||
data-query-context="<?php echo esc_attr((string) $args['query_context']); ?>"
|
||||
<?php endif; ?>
|
||||
<?php echo $args['ajax_attrs']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
>
|
||||
<?php if (!empty($args['show_loading'])) : ?>
|
||||
<div class="archive__ajax-loading" aria-hidden="true"><span class="archive__ajax-spinner"></span></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($has_posts) : ?>
|
||||
<?php
|
||||
if (function_exists('aksrt_render_post_list')) {
|
||||
aksrt_render_post_list($query, array_merge($render_config, ['wrapper_class' => 'content-stream__list']));
|
||||
}
|
||||
?>
|
||||
<div class="content-stream__footer">
|
||||
<?php
|
||||
if (function_exists('aksrt_render_pagination')) {
|
||||
aksrt_render_pagination($query, [
|
||||
'query_context' => (string) $args['query_context'],
|
||||
'render_config' => $render_config,
|
||||
]);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="no-results content-stream__empty">
|
||||
<p><?php echo esc_html((string) $args['empty_text']); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_open_shell')) :
|
||||
/**
|
||||
* Open a shared archive shell.
|
||||
*
|
||||
* @param array<string,mixed> $args Shell args.
|
||||
*/
|
||||
function aksrt_archive_open_shell(array $args = []): void {
|
||||
$args = wp_parse_args($args, [
|
||||
'main_class' => 'site-main container',
|
||||
'has_sidebar' => false,
|
||||
'top_fluid' => [],
|
||||
'page_kind' => 'archive',
|
||||
]);
|
||||
|
||||
$main_class = trim((string) $args['main_class']);
|
||||
?>
|
||||
<main id="main-content" class="<?php echo esc_attr($main_class); ?>" tabindex="-1">
|
||||
<?php
|
||||
if (!empty($args['top_fluid']) && is_array($args['top_fluid'])) {
|
||||
aksrt_archive_render_widget_zone($args['top_fluid'], 'fluid-widget-wrap');
|
||||
}
|
||||
?>
|
||||
<div class="content-wrap">
|
||||
<div class="content-layout<?php echo !empty($args['has_sidebar']) ? '' : ' content-layout--no-sidebar'; ?>">
|
||||
<div class="content-layout__primary">
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_archive_close_shell')) :
|
||||
/**
|
||||
* Close a shared archive shell.
|
||||
*
|
||||
* @param array<string,mixed> $args Shell args.
|
||||
*/
|
||||
function aksrt_archive_close_shell(array $args = []): void {
|
||||
$args = wp_parse_args($args, [
|
||||
'has_sidebar' => false,
|
||||
'bottom_fluid' => [],
|
||||
]);
|
||||
?>
|
||||
</div>
|
||||
<?php if (!empty($args['has_sidebar'])) : ?>
|
||||
<?php get_sidebar(); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if (!empty($args['bottom_fluid']) && is_array($args['bottom_fluid'])) {
|
||||
aksrt_archive_render_widget_zone($args['bottom_fluid'], 'fluid-widget-wrap');
|
||||
}
|
||||
?>
|
||||
</main>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
+192
-189
@@ -47,8 +47,6 @@ $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']);
|
||||
|
||||
$search_sidebar_id = is_active_sidebar('search_sidebar') ? 'search_sidebar' : 'sidebar-blog';
|
||||
$has_sidebar = !empty($other_page_settings['page_search_sidebar']) && is_active_sidebar($search_sidebar_id);
|
||||
$current_orderby = sanitize_key((string) get_query_var('orderby'));
|
||||
$current_order = strtoupper(sanitize_key((string) get_query_var('order')));
|
||||
$current_sort = 'relevance';
|
||||
@@ -84,12 +82,19 @@ if ($current_category > 0 && $search_type === 'post') {
|
||||
|
||||
$search_count = isset($loop_query->found_posts) ? (int) $loop_query->found_posts : 0;
|
||||
|
||||
$render_config = [
|
||||
'context' => 'search',
|
||||
'mode' => (string) ($list_settings['render_mode'] ?? 'card'),
|
||||
'card_style' => (string) ($list_settings['card_style'] ?? 'standard'),
|
||||
'highlight_query' => $search_query,
|
||||
];
|
||||
$render_config = function_exists('aksrt_archive_get_render_config')
|
||||
? aksrt_archive_get_render_config([
|
||||
'context' => 'search',
|
||||
'mode' => (string) ($list_settings['render_mode'] ?? 'card'),
|
||||
'card_style' => (string) ($list_settings['card_style'] ?? 'standard'),
|
||||
'highlight_query' => $search_query,
|
||||
])
|
||||
: [
|
||||
'context' => 'search',
|
||||
'mode' => (string) ($list_settings['render_mode'] ?? 'card'),
|
||||
'card_style' => (string) ($list_settings['card_style'] ?? 'standard'),
|
||||
'highlight_query' => $search_query,
|
||||
];
|
||||
|
||||
$search_sort_options = [
|
||||
'relevance' => [
|
||||
@@ -109,207 +114,205 @@ $search_sort_options = [
|
||||
'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') || is_active_sidebar('sidebar-blog')));
|
||||
|
||||
if (function_exists('aksrt_archive_open_shell')) {
|
||||
aksrt_archive_open_shell([
|
||||
'main_class' => 'site-main container content-shell content-shell--stream',
|
||||
'has_sidebar' => $has_sidebar,
|
||||
'top_fluid' => ['search_top_fluid'],
|
||||
'page_kind' => 'search',
|
||||
]);
|
||||
}
|
||||
?>
|
||||
<?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 id="main-content" class="site-main container" tabindex="-1">
|
||||
<?php if (is_active_sidebar('search_top_fluid')) : ?>
|
||||
<div class="fluid-widget-wrap">
|
||||
<?php dynamic_sidebar('search_top_fluid'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="content-main content-main--search">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<div class="content-wrap">
|
||||
<div class="content-layout<?php echo $has_sidebar ? '' : ' content-layout--no-sidebar'; ?>">
|
||||
<div class="content-layout__primary">
|
||||
<?php if (is_active_sidebar('search_top_content')) { dynamic_sidebar('search_top_content'); } ?>
|
||||
<?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());
|
||||
set_query_var('aksrt_ph_eyebrow', __('站内搜索', 'aksrt'));
|
||||
set_query_var('aksrt_ph_title', $search_title);
|
||||
set_query_var('aksrt_ph_desc', $search_desc);
|
||||
set_query_var('aksrt_ph_extra', $admin_link);
|
||||
get_template_part('templates/parts/page-header');
|
||||
?>
|
||||
|
||||
<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');
|
||||
$admin_link = function_exists('aksrt_render_admin_quick_link') ? aksrt_render_admin_quick_link('page-display/other', __('搜索页设置', 'aksrt')) : '';
|
||||
set_query_var('aksrt_ph_eyebrow', __('站内搜索', 'aksrt'));
|
||||
set_query_var('aksrt_ph_title', $search_title);
|
||||
set_query_var('aksrt_ph_desc', $search_desc);
|
||||
set_query_var('aksrt_ph_extra', $admin_link);
|
||||
get_template_part('templates/parts/page-header');
|
||||
?>
|
||||
|
||||
<section class="content-stream content-stream--search" data-page-kind="search" data-render-mode="<?php echo esc_attr((string) $render_config['mode']); ?>" data-card-style="<?php echo esc_attr((string) $render_config['card_style']); ?>">
|
||||
<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'); ?>">
|
||||
<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-card-style="<?php echo esc_attr((string) $render_config['card_style']); ?>">
|
||||
<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-filters__group">
|
||||
<span class="search-page-filters__label"><?php esc_html_e('类型', 'aksrt'); ?></span>
|
||||
<div class="search-page-filters__chips">
|
||||
<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) : ?>
|
||||
<?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>
|
||||
<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>
|
||||
</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 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['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);
|
||||
<?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) {
|
||||
$sort_url = add_query_arg('aksrt_category', $current_category, $sort_url);
|
||||
$type_args['aksrt_category'] = $current_category;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<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($loop_query, array_merge($render_config, ['wrapper_class' => 'content-stream__list'])); ?>
|
||||
<div class="content-stream__footer">
|
||||
<?php aksrt_render_pagination($loop_query, ['query_context' => 'search', 'render_config' => $render_config]); ?>
|
||||
</div>
|
||||
<?php wp_reset_postdata(); ?>
|
||||
<?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>
|
||||
?>
|
||||
<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; ?>
|
||||
<?php endif; ?>
|
||||
</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; ?>
|
||||
</section>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (is_active_sidebar('search_bottom_content')) { dynamic_sidebar('search_bottom_content'); } ?>
|
||||
</div>
|
||||
<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 ($has_sidebar) : ?>
|
||||
<?php get_sidebar(); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($loop_query->have_posts() && function_exists('aksrt_render_post_list')) : ?>
|
||||
<?php aksrt_render_post_list($loop_query, array_merge($render_config, ['wrapper_class' => 'content-stream__list'])); ?>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<?php if (is_active_sidebar('search_bottom_fluid')) : ?>
|
||||
<div class="fluid-widget-wrap">
|
||||
<?php dynamic_sidebar('search_bottom_fluid'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
<?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
|
||||
if (function_exists('aksrt_archive_close_shell')) {
|
||||
aksrt_archive_close_shell([
|
||||
'has_sidebar' => $has_sidebar,
|
||||
'bottom_fluid' => ['search_bottom_fluid'],
|
||||
]);
|
||||
}
|
||||
|
||||
<?php get_footer(); ?>
|
||||
get_footer();
|
||||
|
||||
@@ -25,10 +25,12 @@ $archive_settings = class_exists('AKSRT_Term_Meta')
|
||||
'show_desc' => !empty($term->description),
|
||||
'cover_url' => '',
|
||||
'description' => (string) $term->description,
|
||||
'card_style' => 'standard',
|
||||
];
|
||||
|
||||
$sidebar_id = is_active_sidebar('tag_sidebar') ? 'tag_sidebar' : 'sidebar-blog';
|
||||
$has_sidebar = !empty($archive_settings['show_sidebar']) && is_active_sidebar($sidebar_id);
|
||||
$has_sidebar = function_exists('aksrt_archive_has_sidebar')
|
||||
? aksrt_archive_has_sidebar('tag_sidebar', !empty($archive_settings['show_sidebar']))
|
||||
: (!empty($archive_settings['show_sidebar']) && (is_active_sidebar('tag_sidebar') || is_active_sidebar('sidebar-blog')));
|
||||
$description = !empty($archive_settings['show_desc']) ? wp_kses_post((string) $archive_settings['description']) : '';
|
||||
$header_style = (string) $archive_settings['header_style'];
|
||||
$layout_mode = (string) $archive_settings['layout_mode'];
|
||||
@@ -40,30 +42,23 @@ if (!empty($filter_settings['enabled']) && !in_array('tag', $filter_settings['cu
|
||||
$filter_settings['enabled'] = false;
|
||||
}
|
||||
$ajax_filter = !empty($filter_settings['ajax_enabled']) && !empty($filter_settings['enabled']);
|
||||
$current_orderby = sanitize_key((string) get_query_var('orderby'));
|
||||
$current_order = strtoupper(sanitize_key((string) get_query_var('order')));
|
||||
$current_sort = 'latest';
|
||||
|
||||
if ($current_orderby === 'date' && $current_order === 'ASC') {
|
||||
$current_sort = 'oldest';
|
||||
} elseif ($current_orderby === 'comment_count') {
|
||||
$current_sort = 'popular';
|
||||
}
|
||||
|
||||
$render_config = [
|
||||
'context' => 'tag',
|
||||
'mode' => $layout_mode,
|
||||
'card_style' => $card_style,
|
||||
];
|
||||
$sort_links = [
|
||||
'latest' => remove_query_arg(['orderby', 'order', 'paged']),
|
||||
'oldest' => add_query_arg(['orderby' => 'date', 'order' => 'asc', 'paged' => false]),
|
||||
'popular' => add_query_arg(['orderby' => 'comment_count', 'order' => 'desc', 'paged' => false]),
|
||||
];
|
||||
$sort_state = function_exists('aksrt_archive_get_sort_state') ? aksrt_archive_get_sort_state() : ['current' => 'latest', 'links' => []];
|
||||
$current_sort = $sort_state['current'];
|
||||
$sort_links = $sort_state['links'];
|
||||
$render_config = function_exists('aksrt_archive_get_render_config')
|
||||
? aksrt_archive_get_render_config([
|
||||
'context' => 'tag',
|
||||
'mode' => $layout_mode,
|
||||
'card_style' => $card_style,
|
||||
])
|
||||
: [
|
||||
'context' => 'tag',
|
||||
'mode' => $layout_mode,
|
||||
'card_style' => $card_style,
|
||||
];
|
||||
|
||||
$cat_filter_terms = [];
|
||||
$current_filter_cat = sanitize_text_field((string) get_query_var('aksrt_filter_cat', ''));
|
||||
$current_filter_tag = sanitize_text_field((string) get_query_var('aksrt_filter_tag', ''));
|
||||
if ($ajax_filter && !empty($filter_settings['tag_show_cat'])) {
|
||||
$cat_filter_terms = get_terms([
|
||||
'taxonomy' => 'category',
|
||||
@@ -75,115 +70,99 @@ if ($ajax_filter && !empty($filter_settings['tag_show_cat'])) {
|
||||
$cat_filter_terms = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_archive_open_shell')) {
|
||||
aksrt_archive_open_shell([
|
||||
'main_class' => 'site-main container content-shell content-shell--stream',
|
||||
'has_sidebar' => $has_sidebar,
|
||||
'top_fluid' => ['tag_top_fluid'],
|
||||
'page_kind' => 'tag',
|
||||
]);
|
||||
}
|
||||
?>
|
||||
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['tag_top_content']); } elseif (is_active_sidebar('tag_top_content')) { dynamic_sidebar('tag_top_content'); } ?>
|
||||
|
||||
<main id="main-content" class="site-main container" tabindex="-1">
|
||||
<?php
|
||||
if (is_active_sidebar('tag_top_fluid')) {
|
||||
echo '<div class="fluid-widget-wrap">';
|
||||
dynamic_sidebar('tag_top_fluid');
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
<div class="content-wrap">
|
||||
<div class="content-layout<?php echo $has_sidebar ? '' : ' content-layout--no-sidebar'; ?>">
|
||||
<div class="content-layout__primary">
|
||||
<div class="content-main content-main--archive content-main--tag">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php if (is_active_sidebar('tag_top_content')) { dynamic_sidebar('tag_top_content'); } ?>
|
||||
|
||||
<div class="content-main content-main--archive content-main--tag">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php if ($header_style !== 'none') : ?>
|
||||
<header class="page-header term-page-header term-page-header--<?php echo esc_attr($header_style); ?><?php echo (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') ? ' has-cover-bg' : ''; ?>">
|
||||
<?php if (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') : ?>
|
||||
<div class="term-page-header__cover-bg" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')">
|
||||
<div class="term-page-header__cover-overlay"></div>
|
||||
<?php if ($header_style !== 'none') : ?>
|
||||
<header class="page-header term-page-header term-page-header--<?php echo esc_attr($header_style); ?><?php echo (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') ? ' has-cover-bg' : ''; ?>">
|
||||
<?php if (!empty($archive_settings['show_cover']) && !empty($archive_settings['cover_url']) && $header_style === 'cover') : ?>
|
||||
<div class="term-page-header__cover-bg" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')">
|
||||
<div class="term-page-header__cover-overlay"></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="term-page-header__body<?php echo $header_style === 'cover' ? ' term-page-header__body--overlay' : ''; ?>">
|
||||
<div>
|
||||
<p class="term-page-header__eyebrow"><?php esc_html_e('标签归档', 'aksrt'); ?></p>
|
||||
<h1 class="entry-title"><?php single_tag_title(); ?></h1>
|
||||
<?php if ($description !== '') : ?>
|
||||
<p class="term-page-header__desc"><?php echo $description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/tag', __('标签页设置', 'aksrt')); } ?>
|
||||
</div>
|
||||
<?php if (!empty($archive_settings['show_cover']) && $header_style !== 'cover') : ?>
|
||||
<div class="term-page-header__cover" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')"></div>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
<div class="term-page-header__body<?php echo $header_style === 'cover' ? ' term-page-header__body--overlay' : ''; ?>">
|
||||
<div>
|
||||
<p class="term-page-header__eyebrow"><?php esc_html_e('标签归档', 'aksrt'); ?></p>
|
||||
<h1 class="entry-title"><?php single_tag_title(); ?></h1>
|
||||
<?php if ($description !== '') : ?>
|
||||
<p class="term-page-header__desc"><?php echo $description; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($filter_settings['enabled']) && (!empty($filter_settings['sort']) || !empty($cat_filter_terms))) : ?>
|
||||
<div class="archive-filter-bar<?php echo $ajax_filter ? ' archive-filter-bar--ajax' : ''; ?>" aria-label="<?php esc_attr_e('标签工具条', 'aksrt'); ?>"<?php if ($ajax_filter) : ?> data-ajax-archive="tag" data-term-id="<?php echo (int) $term->term_id; ?>" data-query-context="archive" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php endif; ?>>
|
||||
<?php if (!empty($cat_filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('分类', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo $current_filter_cat === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url(remove_query_arg(['aksrt_filter_cat'])); ?>"<?php if ($ajax_filter) : ?> data-filter-cat=""<?php endif; ?>><?php esc_html_e('全部', 'aksrt'); ?></a>
|
||||
<?php foreach ($cat_filter_terms as $cat_term) : ?>
|
||||
<?php $is_current_cat = ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $cat_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_cat ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_filter_cat', (int) $cat_term->term_id)); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="<?php echo (int) $cat_term->term_id; ?>"<?php endif; ?>><?php echo esc_html($cat_term->name); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($filter_settings['sort'])) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('排序', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<?php foreach ($sort_links as $sort_key => $sort_url) : ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $current_sort === $sort_key ? ' is-active' : ''; ?>" href="<?php echo esc_url($sort_url); ?>"<?php if ($ajax_filter) : ?> data-filter-sort="<?php echo esc_attr($sort_key); ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($sort_key === 'oldest' ? __('最早', 'aksrt') : ($sort_key === 'popular' ? __('热门', 'aksrt') : __('最新', 'aksrt'))); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="archive-filter-bar__meta">
|
||||
<?php printf(esc_html(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt')), (int) $term->count); ?>
|
||||
</div>
|
||||
<?php if (function_exists('aksrt_render_admin_quick_link')) { aksrt_render_admin_quick_link('page-display/tag', __('标签页设置', 'aksrt')); } ?>
|
||||
</div>
|
||||
<?php if (!empty($archive_settings['show_cover']) && $header_style !== 'cover') : ?>
|
||||
<div class="term-page-header__cover" style="background-image:url('<?php echo esc_url((string) $archive_settings['cover_url']); ?>')"></div>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($filter_settings['enabled']) && (!empty($filter_settings['sort']) || !empty($cat_filter_terms))) : ?>
|
||||
<div class="archive-filter-bar<?php echo $ajax_filter ? ' archive-filter-bar--ajax' : ''; ?>" aria-label="<?php esc_attr_e('标签工具条', 'aksrt'); ?>"<?php if ($ajax_filter) : ?> data-ajax-archive="tag" data-term-id="<?php echo (int) $term->term_id; ?>" data-query-context="archive" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php endif; ?>>
|
||||
<?php if (!empty($cat_filter_terms)) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('分类', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<a class="archive-filter-bar__chip<?php echo $current_filter_cat === '' ? ' is-active' : ''; ?>" href="<?php echo esc_url(remove_query_arg(['aksrt_filter_cat'])); ?>"<?php if ($ajax_filter) : ?> data-filter-cat=""<?php endif; ?>>
|
||||
<?php esc_html_e('全部', 'aksrt'); ?>
|
||||
</a>
|
||||
<?php foreach ($cat_filter_terms as $cat_term) : ?>
|
||||
<?php $is_current_cat = ($current_filter_cat !== '' && (int) $current_filter_cat === (int) $cat_term->term_id); ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $is_current_cat ? ' is-active' : ''; ?>" href="<?php echo esc_url(add_query_arg('aksrt_filter_cat', (int) $cat_term->term_id)); ?>"<?php if ($ajax_filter) : ?> data-filter-cat="<?php echo (int) $cat_term->term_id; ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($cat_term->name); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_render_stream')) {
|
||||
aksrt_archive_render_stream(null, $render_config, [
|
||||
'page_kind' => 'tag',
|
||||
'query_context' => 'archive',
|
||||
'stream_class' => 'archive__ajax-wrap content-stream--archive content-stream--tag',
|
||||
'empty_text' => __('该标签下暂无文章', 'aksrt'),
|
||||
'ajax_enabled' => $ajax_filter,
|
||||
'show_loading' => $ajax_filter,
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (function_exists('aksrt_archive_render_widget_zone')) { aksrt_archive_render_widget_zone(['tag_bottom_content']); } elseif (is_active_sidebar('tag_bottom_content')) { dynamic_sidebar('tag_bottom_content'); } ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($filter_settings['sort'])) : ?>
|
||||
<div class="archive-filter-bar__main">
|
||||
<span class="archive-filter-bar__label"><?php esc_html_e('排序', 'aksrt'); ?></span>
|
||||
<div class="archive-filter-bar__chips">
|
||||
<?php foreach ($sort_links as $sort_key => $sort_url) : ?>
|
||||
<a class="archive-filter-bar__chip<?php echo $current_sort === $sort_key ? ' is-active' : ''; ?>" href="<?php echo esc_url($sort_url); ?>"<?php if ($ajax_filter) : ?> data-filter-sort="<?php echo esc_attr($sort_key); ?>"<?php endif; ?>>
|
||||
<?php echo esc_html($sort_key === 'oldest' ? __('最早', 'aksrt') : ($sort_key === 'popular' ? __('热门', 'aksrt') : __('最新', 'aksrt'))); ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="archive-filter-bar__meta">
|
||||
<?php printf(esc_html(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt')), (int) $term->count); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="archive__ajax-wrap content-stream content-stream--archive content-stream--tag<?php echo $ajax_filter ? ' is-ajax-enabled' : ''; ?>" data-page-kind="tag" data-render-mode="<?php echo esc_attr($layout_mode); ?>" data-card-style="<?php echo esc_attr($card_style); ?>"<?php if ($ajax_filter) : ?> data-ajax-wrap data-query-context="archive"<?php endif; ?>>
|
||||
<div class="archive__ajax-loading" aria-hidden="true"><span class="archive__ajax-spinner"></span></div>
|
||||
<?php if (have_posts()) : ?>
|
||||
<?php aksrt_render_post_list(null, array_merge($render_config, ['wrapper_class' => 'content-stream__list'])); ?>
|
||||
<div class="content-stream__footer">
|
||||
<?php aksrt_render_pagination(null, ['query_context' => 'archive', 'render_config' => $render_config]); ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="no-results content-stream__empty">
|
||||
<p><?php esc_html_e('该标签下暂无文章', 'aksrt'); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (is_active_sidebar('tag_bottom_content')) { dynamic_sidebar('tag_bottom_content'); } ?>
|
||||
</div>
|
||||
|
||||
<?php if ($has_sidebar) : ?>
|
||||
<?php get_sidebar(); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (is_active_sidebar('tag_bottom_fluid')) {
|
||||
echo '<div class="fluid-widget-wrap">';
|
||||
dynamic_sidebar('tag_bottom_fluid');
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
if (function_exists('aksrt_archive_close_shell')) {
|
||||
aksrt_archive_close_shell([
|
||||
'has_sidebar' => $has_sidebar,
|
||||
'bottom_fluid' => ['tag_bottom_fluid'],
|
||||
]);
|
||||
}
|
||||
|
||||
get_footer();
|
||||
|
||||
Reference in New Issue
Block a user