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
+34 -26
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,40 +35,53 @@ 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>
<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 goLogin() {
window.location.href = '/wp-login.php?redirect_to=' + encodeURIComponent(window.location.href);
}
</script>
<?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>
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; ?>
</div>