Files
wordpress-theme-aksrt/.zcode/plans/plan-sess_6d07f1d1-0495-4d41-b29a-3c611a4eeab5.md
T
2026-09-05 17:32:18 +08:00

4.9 KiB
Raw Blame History

侧栏空槽/挤压修复(全站,单一决策源)

根因

"是否渲染侧栏列"有两套脱节的决策:

  • body 布局类(site-layout-1/2/3,决定 CSS 留白)来自 aksrt_is_show_sidebar_filter(),但"小工具是否为空"检查只对 is_single() 生效(inc/helpers/template-tags/site-layout.php:150-152)。
  • aside 渲染各自为政:固定首页 aksrt_homepage_render_sidebar() 额外检查小工具(inc/helpers/homepage/content.php:146-162),空时整个不渲染;sidebar.php(page/search/archive 用)却渲染空列 div("legacy parity")。

于是"开关开 + 无小工具":首页 body 仍是 site-layout-2 → layout.css:156-162 保留 margin-right: 侧栏宽+15px → 主内容挤压、右侧 326px 空槽;其他页面则是空列占位同样挤压。后台关开关的路径本身自洽(layout-1),但因上述不一致,任何"列被保留而无内容"的场景都出现挤压。

参考 Zibll(zib-theme.php 判断 + sidebar.php:14-16 早退 + main.css 留白只挂 site-layout-2/3):判断集中一处,body class 承载几何,渲染与判定同源。AKSRT 骨架已具备,只缺"小工具为空"一维的全局化。

修改

1. inc/helpers/template-tags/site-layout.php — 核心(覆盖所有页面)

  • aksrt_is_show_sidebar_filter():把 is_single() && !aksrt_has_current_sidebar_widgets() 提升为无条件 if (!aksrt_has_current_sidebar_widgets()) { return false; }(空侧栏列 = 空槽,全部场景折叠为 layout-1;single 既有行为不变,home/category/tag/search/page/日期归档一并对齐)。
  • aksrt_resolve_sidebar_id():把 is_home() || is_front_page() 分支移到 is_page() 之前——静态首页目前解析成 page_sidebar_{id} 但渲染器输出 home_sidebar,判定/渲染不匹配;重排后一致(该函数仅 sidebar.php 与小工具检查两处调用,重排安全)。

2. inc/helpers/homepage/content.php — 删双路

  • 删除 aksrt_homepage_has_sidebar()(修复后与 aksrt_is_show_sidebar() 完全等价);aksrt_homepage_render_sidebar() 守卫直接用 !aksrt_is_show_sidebar()。

3. sidebar.php — Zibll 式早退

  • 顶部加 if (!function_exists('aksrt_is_show_sidebar') || !aksrt_is_show_sidebar()) { return; }(覆盖 search.php:126 的无条件 get_sidebar())。
  • 删除"Keep the column even if widgets are empty (legacy parity)"注释与空列行为(此后不可能渲染空列:is_show_sidebar 为真 ⇔ 至少一个 zone 有小工具);删除 elseif ((is_home() || is_front_page()) && ...home_sidebar...) 死分支与 $sidebar_id 兜底。

4. inc/helpers/aksrt-archive.php + category.php / tag.php — 死参数清理

  • aksrt_archive_has_sidebar(string $preferred = '', bool $enabled = true) → (bool $enabled = true)($preferred 自注释 "compat only" 后即 unset,死参数);删除 return !wp_is_mobile(); 死兜底(主题已明确弃用 wp_is_mobile 布局门控,见 site-layout.php:141-143)。
  • 更新调用点:category.php:49、tag.php:30 改为 aksrt_archive_has_sidebar(!empty($archive_settings['show_sidebar']))。

5. 死类/死代码清理

  • single.php:45:删除无任何 CSS/JS 引用的 container--no-sidebar 输出。
  • front-page.php:14-29:删除不可达的 function_exists('aksrt_homepage_render_layout') 兜底双路(inc/bootstrap.php:33 无条件加载),模板直接 get_header(); aksrt_homepage_render_layout(); get_footer();。
  • index.php:23-25:注释"widget activity never changes the body layout after render"与新契约矛盾,更新为单一决策源描述。
  • 保留:layout.css:149-153 的 content-layout--no-sidebar compat 规则(go.php/archive-resources.php/page-ban-appeal.php/page-user-home.php 仍在用)。

6. 测试

  • tests/widget-system/post-visual-contract.test.cjs:359-367:更新测试名与 :364 正则为全局检查 if \(!aksrt_has_current_sidebar_widgets\(\)\) \{\s*return false;;新增断言钉住:homepage 渲染守卫用 aksrt_is_show_sidebar() 且 aksrt_homepage_has_sidebar 已不存在、sidebar.php 早退、resolver 中 home 分支先于 page 分支、archive helper 无 $preferred 参数。
  • 运行 node --test tests/widget-system/(至少 post-visual-contract)与 php -l 全部改动 PHP 文件。

修复后行为矩阵(每场景验证推演)

状态 body 类 aside
开关开 + 有小工具 layout-2/3 渲染,留白匹配
开关开 + 无小工具 layout-1 不渲染,主内容占满(首页/分类/标签/页面/搜索/归档统一)
开关关 layout-1 不渲染

不改动

SPA schema(sidebar_home_enabled 等字段已齐全)、get_sidebar_config() 缺省语义、主题的响应式 CSS 隐藏策略(弃用 wp_is_mobile 的既有决定)、single 页既有判定(已被测试钉住,保持原样)。