3.2.46: 新增 [Archives] 归档短代码 + 评论关闭时整块零输出 #15
需求一:[Archives] 短代码 —— 归档式全站文章列表
· 在文章/页面正文写一行 [Archives],该位置渲染全站文章的年月归档
· 默认显示今年,按月份归类;每篇带浏览/评论/点赞三个数
· 上下两排各有一组「上一年 / 下一年」按钮(四角),JS 切换不刷新页面
· 地址栏同步 ?arc_year=,刷新与分享链接都能保持同一年
· 只在用到短代码的页面才加载 assets/js|css/archives.js|css
· 参数:year="2025" 指定首年;month="0" 不按月分组
需求二:评论关闭时评论区整块消失
· comments.php 在**任何输出之前** `if (!comments_open()) return;`
—— 零字节,不是空容器、不是 display:none、不留提示文字
· 已有评论的老文章关评论后也不再显示(需求原话:正文之外什么都没有)
· inc/theme-comments.php 的资源守卫与之同口径:关评论时不加载
约 10KB 的 comments.css / comments.js
· 删掉 .comments-closed 样式与两处「评论已关闭」提示分支
开发中实测抓到并修掉的三个真实 bug(都是"测试把期望值写对之后"才显形):
· 年份标题 / 导航年份过了 number_format_i18n() ⇒ 输出「2,025」,
而 JS 侧 String(year) 输出「2025」⇒ 首屏与切年后不一致
· 月份标题同样过 number_format_i18n(),与 JS 侧 String(m) 口径不一致
· yang_archives_render_nav() 把 ar-nav-top 写死,而下排也调它生成
⇒ 下排被叫成 top(视觉上被更高特异性规则压住,看不出问题)
验证:
归档 _archives_unit.php 94 通过 / 0 失败
_archives_e2e.js 109 通过 / 0 失败
_archives_e2e_falsify.js 反证 25 真红 / 0 无效
_archives_unit_falsify.py 反证 6 真红 / 0 无效
评论 _comments_closed_test.php 54 通过 / 0 失败
_comments_closed_falsify.py 反证 13 真红 / 0 无效
回归 _test_comments.php 64 通过 / 0 失败
_hl_unit_run.py 24 通过 / 0 失败
全量 96 个 PHP 文件语法检查通过;包内 lint 通过
发布 已推 3.2.46 到 /theme-update/,update.json 已落 3.2.46;
服务器 wp-content/themes/kratos_yang/ 仍为 3.2.45(未覆盖)
另:把 _archives_unit.php 从 `__DIR__` 定位改为接受根目录参数,
否则它无法登记进 verify_all.sh,只能手动跑(手动跑 = 长期不跑)。
5 个新套件已登记进 verify_all.sh(2j ~ 2o)。
This commit is contained in:
+55
-15
@@ -37,6 +37,32 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['S
|
||||
die();
|
||||
}
|
||||
|
||||
/* ── 3.2.46 评论关闭时整块不输出 ──────────────────────────────
|
||||
*
|
||||
* 以前这里会渲染一个 `.comments` 容器,并在里面打一句
|
||||
* 「评论已关闭。」/「评论已关闭,但你可以阅读上面的讨论。」
|
||||
* —— 用户明确要求:**评论一关,这一块整个消失**,
|
||||
* 不留提示文字、不留空容器、已有评论也不再显示。
|
||||
* 正文结束之后直接就是页脚。
|
||||
*
|
||||
* 🔴 为什么是 `return` 而不是把内容包进 `if (comments_open())`:
|
||||
* 包起来的话,容器 `<div class="comments">` 仍会被输出(一个空盒子),
|
||||
* 而主题给 `.comments` 有 margin/padding,页面上会留下一道空白 ——
|
||||
* 看起来像"有个东西没加载出来"。`return` 是**一个字节都不输出**,
|
||||
* 这才是需求要的"什么都没有"。
|
||||
*
|
||||
* 🔴 必须放在**任何输出之前**:这个位置在文件里还没有 echo 过任何东西,
|
||||
* 所以 return 是干净的。一旦挪到后面,前面的 HTML 已经发出去了,
|
||||
* 再加 return 只会得到一个残疾的残块。
|
||||
*
|
||||
* ⚠️ `comments.php` 是被 `comments_template()` include 的,
|
||||
* 在它里面 `return` 只会结束这个模板文件的执行,
|
||||
* 不会中断 single.php / page.php 的后续渲染。
|
||||
*/
|
||||
if (!comments_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
require get_template_directory() . '/pages/page-smilies.php';
|
||||
|
||||
$yang_post_id = get_the_ID();
|
||||
@@ -71,20 +97,20 @@ if ($yang_per_page <= 0) {
|
||||
}
|
||||
?>
|
||||
</h3>
|
||||
<?php if (comments_open()) : ?>
|
||||
<a class="comments-jump-form" href="#respond"><?php esc_html_e('写下你的评论', 'kratos'); ?></a>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
/* 3.2.46:原本是 `if (comments_open())`。文件开头已在评论关闭时
|
||||
return,所以这里恒真,条件已去掉。留着它会让后来人以为
|
||||
"还另有一个关评论的分支"。 */
|
||||
?>
|
||||
<a class="comments-jump-form" href="#respond"><?php esc_html_e('写下你的评论', 'kratos'); ?></a>
|
||||
</div>
|
||||
|
||||
<?php if (!comments_open() && $yang_comment_count === 0) : ?>
|
||||
|
||||
<p class="comments-closed"><?php esc_html_e('评论已关闭。', 'kratos'); ?></p>
|
||||
|
||||
<?php elseif (!comments_open()) : ?>
|
||||
|
||||
<p class="comments-closed"><?php esc_html_e('评论已关闭,但你可以阅读上面的讨论。', 'kratos'); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
/* 3.2.46 起这里不再有「评论已关闭」提示分支:
|
||||
文件开头已经 `if (!comments_open()) return;`,走不到这一行。
|
||||
原先两句「评论已关闭。」「评论已关闭,但你可以阅读上面的讨论。」
|
||||
是用户明确要求删掉的 —— 关评论就该整块消失。 */
|
||||
?>
|
||||
|
||||
<?php if ($yang_has_comments) : ?>
|
||||
<?php
|
||||
@@ -135,13 +161,24 @@ if ($yang_per_page <= 0) {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php elseif (comments_open()) : ?>
|
||||
<?php
|
||||
/* 3.2.46:这里原本是 `elseif (comments_open())`。文件开头已经
|
||||
在评论关闭时 `return`,所以走到这里时 comments_open() **恒真** ——
|
||||
保留那个条件只会变成一句永远为真的死判断,后来人读到这里会
|
||||
以为"还有个关评论的分支要照顾"。改成 else。 */
|
||||
?>
|
||||
<?php else : ?>
|
||||
|
||||
<p class="comments-empty"><?php esc_html_e('还没有评论,来说第一句吧。', 'kratos'); ?></p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (comments_open()) : ?>
|
||||
<?php
|
||||
/* 3.2.46:原本是 `if (comments_open())`,同上,恒真,已去掉条件。
|
||||
下面的登录提示 / 评论表单因此只在"评论开放"时才走到这里 ——
|
||||
这正是需求要的:关评论时整块不输出(而且文件开头就 return 了,
|
||||
连外层 .comments 容器都不会有)。 */
|
||||
?>
|
||||
|
||||
<?php if (get_option('comment_registration') && !is_user_logged_in()) : ?>
|
||||
|
||||
@@ -416,5 +453,8 @@ if ($yang_per_page <= 0) {
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php /* 3.2.46:原来这里还有一个 `endif;` 关掉外层的
|
||||
`if (comments_open())`。那个条件已删除,所以这里也少了对应的
|
||||
endif —— 多的那个会导致 "syntax error"。 */ ?>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user