fix(sidebar): collapse empty sidebar column on every scene

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).
This commit is contained in:
2026-09-05 15:40:11 +08:00
parent 2bf9b00022
commit 1839150ecb
10 changed files with 64 additions and 70 deletions
+10 -9
View File
@@ -1,19 +1,22 @@
<?php
/**
* Sidebar template for generic pages.
* Sidebar template for generic pages (archive / page / search streams).
*
* Single/home own their asides. This template only serves archive/page contexts.
* Callers only include this when aksrt_is_show_sidebar() is true.
* Keep the column even if widgets are empty (legacy parity).
* Single/home own their asides. Renders nothing when the sidebar is disabled
* or its widget stack is empty: aksrt_is_show_sidebar() is the single
* visibility decision and the body site-layout-* class carries the geometry,
* so an empty column is never rendered just to hold a reserved gutter.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$sidebar_id = function_exists('aksrt_resolve_sidebar_id')
? aksrt_resolve_sidebar_id()
: 'home_sidebar';
if (!function_exists('aksrt_is_show_sidebar') || !aksrt_is_show_sidebar()) {
return;
}
$sidebar_id = aksrt_resolve_sidebar_id();
?>
<div class="sidebar" role="complementary" aria-label="<?php esc_attr_e('侧栏', 'aksrt'); ?>">
@@ -23,8 +26,6 @@ $sidebar_id = function_exists('aksrt_resolve_sidebar_id')
<?php if (is_active_sidebar($sidebar_id)) : ?>
<?php dynamic_sidebar($sidebar_id); ?>
<?php elseif ((is_home() || is_front_page()) && is_active_sidebar('home_sidebar')) : ?>
<?php dynamic_sidebar('home_sidebar'); ?>
<?php endif; ?>
<?php if (is_active_sidebar('all_sidebar_bottom')) : ?>