v1.9 — 评论区优化
- 评论列表自定义渲染(头像 22px,回复按钮中文化) - 回复表单标题中文化('回复 %s' / '取消回复') - 去掉 'X条留言' 标题,使用'笺下留言' - 登录弹窗替代 alert - 退出登录+登录带回跳
This commit is contained in:
+13
-35
@@ -1,51 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* 空笺未寄 — Comments Template
|
* 空笺未寄 — 评论模板
|
||||||
* 保留 WP 原生评论区,适配主题样式
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (post_password_required()) return;
|
if (post_password_required()) return;
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div id="comments" class="comments-section">
|
<div id="comments" class="comments-section">
|
||||||
|
|
||||||
<?php if (have_comments()) : ?>
|
<h3 class="comment-reply-title">笺下留言</h3>
|
||||||
<h3 class="comments-title">
|
|
||||||
<?php
|
|
||||||
$comment_count = get_comments_number();
|
|
||||||
if ($comment_count === 1) {
|
|
||||||
echo '一条留言';
|
|
||||||
} else {
|
|
||||||
echo $comment_count . ' 条留言';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
|
<?php if (have_comments()) : ?>
|
||||||
<ol class="comment-list">
|
<ol class="comment-list">
|
||||||
<?php
|
<?php
|
||||||
wp_list_comments(array(
|
wp_list_comments(array(
|
||||||
'style' => 'ol',
|
'style' => 'ol',
|
||||||
'avatar_size' => 32,
|
'avatar_size' => 24,
|
||||||
'short_ping' => true,
|
'short_ping' => true,
|
||||||
|
'callback' => null,
|
||||||
|
'reply_text' => '回复',
|
||||||
|
'format' => 'html5',
|
||||||
));
|
));
|
||||||
?>
|
?>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<?php the_comments_navigation(); ?>
|
<?php the_comments_navigation(); ?>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if (!comments_open() && get_comments_number()) : ?>
|
<?php if (is_user_logged_in()) : ?>
|
||||||
<p class="no-comments">评论已关闭。</p>
|
<?php
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
if (is_user_logged_in()) :
|
|
||||||
// 登录后:只显示留言框 + 按钮,隐藏 "Logged in as XXX"
|
|
||||||
comment_form(array(
|
comment_form(array(
|
||||||
'title_reply' => '笺下留言',
|
'title_reply' => '',
|
||||||
'title_reply_before' => '<h3 class="comment-reply-title">',
|
|
||||||
'title_reply_after' => '</h3>',
|
|
||||||
'comment_notes_before' => '',
|
'comment_notes_before' => '',
|
||||||
'comment_notes_after' => '',
|
'comment_notes_after' => '',
|
||||||
'logged_in_as' => '',
|
'logged_in_as' => '',
|
||||||
@@ -55,10 +38,8 @@ if (post_password_required()) return;
|
|||||||
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
|
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
|
||||||
'label_submit' => '落笔留痕',
|
'label_submit' => '落笔留痕',
|
||||||
));
|
));
|
||||||
else :
|
?>
|
||||||
// 未登录:只显示输入框 + 按钮,提交时提示登录
|
<?php else : ?>
|
||||||
?>
|
|
||||||
<h3 class="comment-reply-title">笺下留言</h3>
|
|
||||||
<form id="commentform-guest" class="comment-form" novalidate>
|
<form id="commentform-guest" class="comment-form" novalidate>
|
||||||
<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>
|
<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>
|
||||||
<div class="form-submit">
|
<div class="form-submit">
|
||||||
@@ -68,12 +49,9 @@ if (post_password_required()) return;
|
|||||||
<script>
|
<script>
|
||||||
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
|
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showLoginModal();
|
|
||||||
});
|
|
||||||
function showLoginModal() {
|
|
||||||
var m = document.getElementById('login-modal');
|
var m = document.getElementById('login-modal');
|
||||||
if (m) m.classList.add('active');
|
if (m) m.classList.add('active');
|
||||||
}
|
});
|
||||||
function closeLoginModal() {
|
function closeLoginModal() {
|
||||||
var m = document.getElementById('login-modal');
|
var m = document.getElementById('login-modal');
|
||||||
if (m) m.classList.remove('active');
|
if (m) m.classList.remove('active');
|
||||||
|
|||||||
@@ -272,3 +272,12 @@ add_filter('comment_post_redirect', function($loc, $comment) {
|
|||||||
|
|
||||||
// 中国时区
|
// 中国时区
|
||||||
date_default_timezone_set('Asia/Shanghai');
|
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;
|
||||||
|
});
|
||||||
|
|||||||
@@ -568,3 +568,15 @@ echo "done"
|
|||||||
.login-modal__btn--cancel { background:var(--border); color:var(--ink-light); }
|
.login-modal__btn--cancel { background:var(--border); color:var(--ink-light); }
|
||||||
.login-modal__btn--go { background:var(--cinnabar); color:#fff; }
|
.login-modal__btn--go { background:var(--cinnabar); color:#fff; }
|
||||||
.login-modal__btn--go:hover { background:#a03a32; }
|
.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; }
|
||||||
|
|||||||
Reference in New Issue
Block a user