Sidebar visibility had two disconnected decisions: the body site-layout-* class (via aksrt_is_show_sidebar_filter) only checked widget activity for singles, while the homepage aside renderer skipped the column and sidebar.php rendered an empty one. With the toggle on and no widgets, the homepage kept a reserved gutter and squeezed the main content aside. - collapse every scene to no-sidebar when the sidebar widget stack is empty - resolve home_sidebar before the page branch so a static front page is checked against the zones the homepage renders - guard the homepage aside with aksrt_is_show_sidebar() alone and drop the duplicate aksrt_homepage_has_sidebar gate - early-return sidebar.php instead of rendering an empty column - drop dead code: archive helper $preferred param, wp_is_mobile fallback, container--no-sidebar class, unreachable front-page fallback - update post-visual-contract to pin the single visibility decision Verification: php -l on all changed files; node --test tests/widget-system/*.test.cjs 242/243 (the toast-contract failure is pre-existing and unrelated).
148 lines
5.5 KiB
PHP
148 lines
5.5 KiB
PHP
<?php
|
|
/**
|
|
* Category archive template.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
get_header();
|
|
|
|
$term = get_queried_object();
|
|
if (class_exists('\AKSRT\Core\DocsPresenter')) {
|
|
$docs_presenter = \AKSRT\Core\DocsPresenter::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();
|
|
return;
|
|
}
|
|
|
|
$archive_settings = class_exists('\AKSRT\Core\TermMeta')
|
|
? \AKSRT\Core\TermMeta::resolve_archive_settings($term)
|
|
: [
|
|
'header_style' => 'cover',
|
|
'show_sidebar' => true,
|
|
'show_cover' => false,
|
|
'show_desc' => !empty($term->description),
|
|
'filter_bar' => true,
|
|
'cover_url' => '',
|
|
'description' => (string) $term->description,
|
|
];
|
|
|
|
$has_sidebar = function_exists('aksrt_archive_has_sidebar')
|
|
? aksrt_archive_has_sidebar(!empty($archive_settings['show_sidebar']))
|
|
: (!empty($archive_settings['show_sidebar']) && is_active_sidebar('cat_sidebar'));
|
|
$description = !empty($archive_settings['show_desc']) ? wp_kses_post((string) $archive_settings['description']) : '';
|
|
$header_style = (string) $archive_settings['header_style'];
|
|
$ajax_filter = !empty($archive_settings['filter_bar']);
|
|
$sort_state = function_exists('aksrt_archive_get_sort_state')
|
|
? aksrt_archive_get_sort_state((array) ($archive_settings['orderby_option'] ?? []))
|
|
: ['current' => 'date', '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'])
|
|
: ['context' => 'category'];
|
|
|
|
$filter_groups = [];
|
|
if (!empty($archive_settings['ajax_category_enabled']) && function_exists('aksrt_archive_build_term_filter_group')) {
|
|
$group = aksrt_archive_build_term_filter_group('category', (array) ($archive_settings['ajax_category'] ?? []), __('分类', 'aksrt'), $ajax_filter);
|
|
if ($group !== []) {
|
|
$filter_groups[] = $group;
|
|
}
|
|
}
|
|
if (!empty($archive_settings['ajax_tag_enabled']) && function_exists('aksrt_archive_build_term_filter_group')) {
|
|
$group = aksrt_archive_build_term_filter_group('post_tag', (array) ($archive_settings['ajax_tag'] ?? []), __('标签', 'aksrt'), $ajax_filter);
|
|
if ($group !== []) {
|
|
$filter_groups[] = $group;
|
|
}
|
|
}
|
|
|
|
if (function_exists('aksrt_archive_open_shell')) {
|
|
aksrt_archive_open_shell([
|
|
'main_class' => 'site-main container',
|
|
'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'); } ?>
|
|
|
|
<div class="content-main content-main--archive content-main--category">
|
|
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
|
|
|
<?php
|
|
if (function_exists('aksrt_archive_render_term_header')) {
|
|
aksrt_archive_render_term_header([
|
|
'header_style' => $header_style,
|
|
'show_cover' => !empty($archive_settings['show_cover']),
|
|
'cover_url' => (string) ($archive_settings['cover_url'] ?? ''),
|
|
'eyebrow' => __('分类归档', 'aksrt'),
|
|
'title' => single_cat_title('', false),
|
|
'description' => $description,
|
|
'admin_path' => 'page-display/category',
|
|
'admin_label' => __('分类页设置', 'aksrt'),
|
|
]);
|
|
}
|
|
?>
|
|
|
|
<?php
|
|
if (!empty($archive_settings['filter_bar']) && function_exists('aksrt_archive_render_filter_bar')) {
|
|
aksrt_archive_render_filter_bar([
|
|
'ajax' => $ajax_filter,
|
|
'ajax_archive' => 'category',
|
|
'term_id' => (int) $term->term_id,
|
|
'aria_label' => __('分类筛选', 'aksrt'),
|
|
'meta_text' => !empty($archive_settings['post_count']) ? sprintf(_n('%d 篇文章', '%d 篇文章', (int) $term->count, 'aksrt'), (int) $term->count) : '',
|
|
'groups' => $filter_groups,
|
|
'sort_enabled' => !empty($archive_settings['orderby_enabled']),
|
|
'sort_current' => $current_sort,
|
|
'sort_links' => $sort_links,
|
|
'sort_labels' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::homepage_sort_labels() : [],
|
|
'sort_as_main' => false,
|
|
]);
|
|
}
|
|
?>
|
|
|
|
<?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
|
|
if (function_exists('aksrt_archive_close_shell')) {
|
|
aksrt_archive_close_shell([
|
|
'has_sidebar' => $has_sidebar,
|
|
'bottom_fluid' => ['cat_bottom_fluid'],
|
|
]);
|
|
}
|
|
|
|
get_footer();
|