69 lines
2.9 KiB
PHP
69 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* 空笺未寄 — 评论模板
|
|
*/
|
|
if (post_password_required()) return;
|
|
?>
|
|
|
|
<div id="comments" class="comments-section">
|
|
|
|
|
|
<?php if (have_comments()) : ?>
|
|
<ol class="comment-list">
|
|
<?php
|
|
$comments = get_comments(array('post_id' => get_the_ID(), 'status' => 'approve', 'order' => 'ASC'));
|
|
foreach ($comments as $c) :
|
|
$c_user = get_user_by('email', $c->comment_author_email);
|
|
?>
|
|
<li class="comment-item">
|
|
<div class="comment-item__meta">
|
|
<?php echo get_avatar($c, 22, '', '', array('class' => 'comment-avatar')); ?>
|
|
<span class="comment-item__author"><?php echo esc_html($c->comment_author); ?></span>
|
|
<span class="comment-item__time"><?php echo get_comment_date('Y-m-d H:i:s', $c); ?></span>
|
|
</div>
|
|
<div class="comment-item__text"><?php echo esc_html($c->comment_content); ?></div>
|
|
<div class="comment-item__reply"><a href="<?php echo esc_url(add_query_arg('replytocom', $c->comment_ID, get_permalink() . '#respond')); ?>">回复</a></div>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ol>
|
|
<?php endif; ?>
|
|
|
|
<?php if (is_user_logged_in()) : ?>
|
|
<?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>',
|
|
'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>
|
|
<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; ?>
|
|
|
|
</div>
|