统一 archive/category/tag/search 主内容流壳层

抽出 aksrt-archive 共享 shell/stream/render config,
四类列表页统一 content-shell + shared renderer + page-owned sidebar。
This commit is contained in:
2026-07-09 22:10:43 +08:00
parent 91945e2006
commit a9ee8c451f
6 changed files with 777 additions and 555 deletions
+41 -61
View File
@@ -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,16 +33,26 @@ if (is_author()) {
(int) $wp_query->found_posts
);
}
?>
<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">
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(); } ?>
<?php
$admin_link = function_exists('aksrt_render_admin_quick_link') ? aksrt_render_admin_quick_link('post-list/list', __('列表样式设置', 'aksrt')) : '';
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);
@@ -78,26 +60,24 @@ if (is_author()) {
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]); ?>
<?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 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
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();
+54 -83
View File
@@ -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 = [
$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,
];
$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]),
];
])
: [
'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,21 +119,17 @@ 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',
]);
}
?>
<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">
<?php if (is_active_sidebar('cat_top_content')) { dynamic_sidebar('cat_top_content'); } ?>
<?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'); } ?>
<div class="content-main content-main--archive content-main--category">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
@@ -174,37 +163,32 @@ if ($ajax_filter && !empty($filter_settings['cat_show_tag'])) {
<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>
<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>
<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 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>
<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>
<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) : ?>
@@ -214,19 +198,16 @@ if ($ajax_filter && !empty($filter_settings['cat_show_tag'])) {
<?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>
<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>
<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>
@@ -234,37 +215,27 @@ if ($ajax_filter && !empty($filter_settings['cat_show_tag'])) {
</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>';
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,
]);
}
?>
</main>
<?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
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell([
'has_sidebar' => $has_sidebar,
'bottom_fluid' => ['cat_bottom_fluid'],
]);
}
get_footer();
+1
View File
@@ -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';
+288
View File
@@ -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;
+40 -37
View File
@@ -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 = [
$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,31 +114,37 @@ $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',
]);
}
?>
<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-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 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'); } ?>
<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))
? 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')) : '';
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);
@@ -141,7 +152,7 @@ $search_sort_options = [
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']); ?>">
<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) : ?>
@@ -266,12 +277,11 @@ $search_sort_options = [
<?php endif; ?>
</div>
<?php if ($loop_query->have_posts()) : ?>
<?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 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>
@@ -296,20 +306,13 @@ $search_sort_options = [
</section>
</div>
<?php if (is_active_sidebar('search_bottom_content')) { dynamic_sidebar('search_bottom_content'); } ?>
</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
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell([
'has_sidebar' => $has_sidebar,
'bottom_fluid' => ['search_bottom_fluid'],
]);
}
<?php if ($has_sidebar) : ?>
<?php get_sidebar(); ?>
<?php endif; ?>
</div>
</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 get_footer(); ?>
get_footer();
+47 -68
View File
@@ -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 = [
$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,
];
$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]),
];
])
: [
'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,21 +70,17 @@ 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',
]);
}
?>
<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">
<?php if (is_active_sidebar('tag_top_content')) { dynamic_sidebar('tag_top_content'); } ?>
<?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'); } ?>
<div class="content-main content-main--archive content-main--tag">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
@@ -123,18 +114,15 @@ if ($ajax_filter && !empty($filter_settings['tag_show_cat'])) {
<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>
<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>
<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>
@@ -147,43 +135,34 @@ if ($ajax_filter && !empty($filter_settings['tag_show_cat'])) {
</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>';
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,
]);
}
?>
</main>
<?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
if (function_exists('aksrt_archive_close_shell')) {
aksrt_archive_close_shell([
'has_sidebar' => $has_sidebar,
'bottom_fluid' => ['tag_bottom_fluid'],
]);
}
get_footer();