fix: 评论回复弹窗 + 登录用户始终显示输入框 + 提示字体缩小

This commit is contained in:
2026-05-17 13:06:05 +08:00
parent b0aa37f3fb
commit 59c52a8bd6
2 changed files with 41 additions and 27 deletions
+28 -20
View File
@@ -7,7 +7,6 @@ if (post_password_required()) return;
<div id="comments" class="comments-section">
<?php if (have_comments()) : ?>
<h3 class="comment-reply-title">笺下留言</h3>
<ol class="comment-list">
@@ -28,11 +27,7 @@ if (post_password_required()) return;
</div>
<div class="comment-item__text"><?php echo esc_html($c->comment_content); ?></div>
<div class="comment-item__reply">
<?php if (is_user_logged_in()) : ?>
<a href="<?php echo esc_url(add_query_arg('replytocom', $c->comment_ID, get_permalink() . '#respond')); ?>">回复</a>
<?php else : ?>
<a href="javascript:void(0)" onclick="goLogin()">回复</a>
<?php endif; ?>
<a href="javascript:void(0)" onclick="replyTo(<?php echo $c->comment_ID; ?>)">回复</a>
</div>
</li>
<?php endforeach; ?>
@@ -40,39 +35,52 @@ if (post_password_required()) return;
<?php endif; ?>
<?php if (is_user_logged_in()) : ?>
<?php
comment_form(array(
<?php comment_form(array(
'title_reply' => '',
'comment_notes_before' => '',
'comment_notes_after' => '',
'logged_in_as' => '',
'fields' => array(),
'comment_field' => '<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>',
'comment_field' => '<textarea id="comment" name="comment" rows="3" placeholder="写点什么..." required></textarea>',
'submit_button' => '<button type="submit" class="submit">落笔留痕</button>',
'submit_field' => '<div class="form-submit">%1$s %2$s</div>',
'label_submit' => '落笔留痕',
));
?>
)); ?>
<?php else : ?>
<form id="commentform-guest" class="comment-form" novalidate>
<textarea id="comment" name="comment" rows="4" placeholder="写点什么..." required></textarea>
<textarea id="comment" name="comment" rows="3" placeholder="写点什么..." required></textarea>
<input type="hidden" id="comment_parent" name="comment_parent" value="0">
<div class="form-submit">
<button type="submit" class="submit">落笔留痕</button>
</div>
</form>
<?php endif; ?>
<?php if (!is_user_logged_in()) : ?>
<div id="login-modal" class="login-modal" style="display:none">
<div class="login-modal__content">
<p>登录后才能留言</p>
<button onclick="goLogin()" class="submit">去登录</button>
<button onclick="closeLoginModal()" class="cancel-btn">取消</button>
</div>
</div>
<script>
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
e.preventDefault();
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');
function replyTo(cid) {
document.getElementById('comment_parent').value = cid;
document.getElementById('comment').focus();
}
function goLogin() {
window.location.href = '/wp-login.php?redirect_to=' + encodeURIComponent(window.location.href);
}
function closeLoginModal() {
var m = document.getElementById('login-modal');
if (m) m.style.display = 'none';
}
document.getElementById('commentform-guest').addEventListener('submit', function(e) {
e.preventDefault();
var m = document.getElementById('login-modal');
if (m) m.style.display = 'flex';
});
</script>
<?php endif; ?>
+7 -1
View File
@@ -1,6 +1,6 @@
/*
Theme Name: 空笺未寄
Version: 0.16.4
Version: 0.16.5
Requires at least: 6.0
Requires PHP: 7.4
License: MIT
@@ -147,8 +147,14 @@ Text Domain: kj-weji
.comment-form { margin-top:24px; display:flex; flex-direction:column; gap:12px; }
.comment-form textarea { width:100%; padding:14px; border:1px solid var(--border); border-radius:var(--radius); background:var(--white); font-family:inherit; font-size:14px; color:var(--ink); resize:vertical; min-height:80px; }
.comment-respond h3, #reply-title { font-size:14px !important; font-weight:600; margin-bottom:12px; }
.comment-form button { align-self:flex-end; background:var(--cinnabar); color:#fff; border:none; padding:8px 24px; border-radius:20px; cursor:pointer; font-family:"Noto Sans SC","PingFang SC","Microsoft YaHei",sans-serif; font-size:13px; transition:background 0.2s; }
.comment-form button:hover { background:#a03a32; }
.cancel-btn { font-size:13px; color:var(--ink-lighter); background:none; border:1px solid var(--border); padding:8px 24px; border-radius:20px; cursor:pointer; }
.login-modal { display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.4); z-index:300; align-items:center; justify-content:center; }
.login-modal__content { background:var(--white); padding:32px; border-radius:var(--radius-lg); text-align:center; box-shadow:0 4px 24px rgba(0,0,0,0.2); }
.login-modal__content p { margin-bottom:16px; font-size:15px; color:var(--ink); }
.login-modal__content button { margin:0 6px; }
/* 吐槽 */
.tucao-item { padding:15px 0; border-bottom:1px solid var(--border-light); }