v1.9 — 评论区优化

- 评论列表自定义渲染(头像 22px,回复按钮中文化)
- 回复表单标题中文化('回复 %s' / '取消回复')
- 去掉 'X条留言' 标题,使用'笺下留言'
- 登录弹窗替代 alert
- 退出登录+登录带回跳
This commit is contained in:
2026-05-04 13:46:15 +08:00
parent f09f3bbfef
commit fef6379522
3 changed files with 34 additions and 35 deletions
+11 -33
View File
@@ -1,51 +1,34 @@
<?php
/**
* 空笺未寄 — Comments Template
* 保留 WP 原生评论区,适配主题样式
* 空笺未寄 — 评论模板
*/
if (post_password_required()) return;
?>
<div id="comments" class="comments-section">
<?php if (have_comments()) : ?>
<h3 class="comments-title">
<?php
$comment_count = get_comments_number();
if ($comment_count === 1) {
echo '一条留言';
} else {
echo $comment_count . ' 条留言';
}
?>
</h3>
<h3 class="comment-reply-title">笺下留言</h3>
<?php if (have_comments()) : ?>
<ol class="comment-list">
<?php
wp_list_comments(array(
'style' => 'ol',
'avatar_size' => 32,
'avatar_size' => 24,
'short_ping' => true,
'callback' => null,
'reply_text' => '回复',
'format' => 'html5',
));
?>
</ol>
<?php the_comments_navigation(); ?>
<?php endif; ?>
<?php if (!comments_open() && get_comments_number()) : ?>
<p class="no-comments">评论已关闭。</p>
<?php endif; ?>
<?php if (is_user_logged_in()) : ?>
<?php
if (is_user_logged_in()) :
// 登录后:只显示留言框 + 按钮,隐藏 "Logged in as XXX"
comment_form(array(
'title_reply' => '笺下留言',
'title_reply_before' => '<h3 class="comment-reply-title">',
'title_reply_after' => '</h3>',
'title_reply' => '',
'comment_notes_before' => '',
'comment_notes_after' => '',
'logged_in_as' => '',
@@ -55,10 +38,8 @@ if (post_password_required()) return;
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
'label_submit' => '落笔留痕',
));
else :
// 未登录:只显示输入框 + 按钮,提交时提示登录
?>
<h3 class="comment-reply-title">笺下留言</h3>
<?php else : ?>
<form id="commentform-guest" class="comment-form" novalidate>
<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>
<div class="form-submit">
@@ -68,12 +49,9 @@ if (post_password_required()) return;
<script>
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
e.preventDefault();
showLoginModal();
});
function showLoginModal() {
var m = document.getElementById('login-modal');
if (m) m.classList.add('active');
}
});
function closeLoginModal() {
var m = document.getElementById('login-modal');
if (m) m.classList.remove('active');
+9
View File
@@ -272,3 +272,12 @@ add_filter('comment_post_redirect', function($loc, $comment) {
// 中国时区
date_default_timezone_set('Asia/Shanghai');
// 评论回复标题中文化
add_filter('comment_form_defaults', function($defaults) {
$defaults['title_reply_to'] = '回复 %s';
$defaults['cancel_reply_link'] = '取消回复';
$defaults['title_reply_before'] = '<h3 class="comment-reply-title">';
$defaults['title_reply_after'] = '</h3>';
return $defaults;
});
+12
View File
@@ -568,3 +568,15 @@ echo "done"
.login-modal__btn--cancel { background:var(--border); color:var(--ink-light); }
.login-modal__btn--go { background:var(--cinnabar); color:#fff; }
.login-modal__btn--go:hover { background:#a03a32; }
.comment-list li { list-style:none; padding:14px 0; border-bottom:1px solid var(--border-light); }
.comment-list .comment-body p { margin:4px 0; font-size:14px; color:var(--ink-light); line-height:1.8; }
.comment-list .comment-author { font-size:13px; font-weight:600; }
.comment-list .comment-author img { width:22px !important; height:22px !important; border-radius:50% !important; object-fit:cover !important; vertical-align:middle; margin-right:4px; }
.comment-list .comment-metadata { font-size:11px; color:var(--ink-lighter); }
.comment-list .comment-metadata a { color:var(--ink-lighter); text-decoration:none; }
.comment-list .reply { font-size:12px; }
.comment-list .reply a { color:var(--cinnabar); text-decoration:none; }
.comment-list .comment-respond { margin-top:12px; padding:12px; background:var(--paper-warm); border-radius:var(--radius); }
.comment-list .children { margin-left:24px; padding-left:0; border-left:2px solid var(--border-light); }
.comment-list .children li { border-bottom:none; }