Files
kjweiji/comments.php
T
liaoxin ee5fa5e7bb v1.7 — 登录态 + 评论优化
- 隐藏 WP admin bar
- 导航栏右侧登录用户头像+姓名下拉菜单
- 笺文评论:只显示输入框+按钮,未登录点提交提示登录
- 评论无需审核直接显示
2026-05-04 03:03:32 +08:00

79 lines
2.6 KiB
PHP

<?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>
<ol class="comment-list">
<?php
wp_list_comments(array(
'style' => 'ol',
'avatar_size' => 32,
'short_ping' => true,
));
?>
</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()) :
// 登录后:只显示留言框 + 按钮,隐藏 "Logged in as XXX"
comment_form(array(
'title_reply' => '笺下留言',
'title_reply_before' => '<h3 class="comment-reply-title">',
'title_reply_after' => '</h3>',
'comment_notes_before' => '',
'comment_notes_after' => '',
'logged_in_as' => '',
'fields' => array(),
'comment_field' => '<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>',
'submit_button' => '<button type="submit" class="submit">落笔留痕</button>',
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
'label_submit' => '落笔留痕',
));
else :
// 未登录:只显示输入框 + 按钮,提交时提示登录
?>
<h3 class="comment-reply-title">笺下留言</h3>
<form id="commentform-guest" class="comment-form" novalidate>
<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>
<div class="form-submit">
<button type="submit" class="submit">落笔留痕</button>
</div>
</form>
<script>
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
e.preventDefault();
if (confirm('请先登录')) {
window.location.href = '/wp-login.php';
}
});
</script>
<?php endif; ?>
</div>