v1.5 — 微言评论 + Photo 画廊
微言评论: - 需登录后留言,未登录提示 - PHP 后端渲染评论,本地证件照头像 - 平级评论 + @回复引用 - 时间线 ASC 排列 - 评论无需审核直接显示 - tucao 禁用单独详情页 - 评论后锚点定位回列表 Photo 画廊: - 灯箱全屏查看,多图左右切换 - 单图/边界隐藏方向键 - 图片去重 - 顶部显示标题·作者
This commit is contained in:
+35
-14
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* 微言归档页 — 带评论
|
||||
* 微言归档页 — 带 AJAX 评论 + 登录验证
|
||||
*/
|
||||
get_header();
|
||||
?>
|
||||
@@ -19,22 +19,38 @@ get_header();
|
||||
<span class="tucao-time"><?php echo get_the_time('Y-m-d H:i'); ?></span>
|
||||
</div>
|
||||
<div class="tucao-body"><?php the_content(); ?></div>
|
||||
<?php
|
||||
$comment_count = get_comments_number();
|
||||
?>
|
||||
<span class="tucao-comments-toggle" onclick="document.getElementById('tucao-comments-<?php the_ID(); ?>').classList.toggle('open')">💬 <?php echo $comment_count; ?> 条留言</span>
|
||||
<?php $comment_count = get_comments_number(); ?>
|
||||
<span class="tucao-comments-toggle" onclick="var el=document.getElementById('tucao-comments-<?php the_ID(); ?>'); el.classList.toggle('open');">💬 <?php echo $comment_count; ?> 条留言</span>
|
||||
<div class="tucao-comments" id="tucao-comments-<?php the_ID(); ?>">
|
||||
<?php
|
||||
$comments = get_comments(array('post_id' => get_the_ID(), 'status' => 'approve'));
|
||||
foreach ($comments as $c) {
|
||||
echo '<div class="tucao-comment"><span class="tucao-comment-author">' . esc_html($c->comment_author) . '</span> · ' . esc_html($c->comment_date) . '<br>' . esc_html($c->comment_content) . '</div>';
|
||||
}
|
||||
$comments = get_comments(array('post_id' => get_the_ID(), 'status' => 'approve', 'order' => 'ASC'));
|
||||
foreach ($comments as $c) :
|
||||
$reply_to = $c->comment_parent ? get_comment($c->comment_parent) : null;
|
||||
?>
|
||||
<form action="<?php echo site_url('/wp-comments-post.php'); ?>" method="post" class="tucao-comment-form">
|
||||
<input type="hidden" name="comment_post_ID" value="<?php the_ID(); ?>">
|
||||
<input type="text" name="comment" placeholder="说点什么...">
|
||||
<button type="submit">落笔</button>
|
||||
</form>
|
||||
<div class="tucao-comment">
|
||||
<div class="tucao-comment-meta">
|
||||
<?php echo get_avatar($c, 16, '', '', array('class' => 'tucao-comment-avatar')); ?>
|
||||
<span class="tucao-comment-author"><?php echo esc_html($c->comment_author); ?></span>
|
||||
<?php if ($reply_to) : ?>
|
||||
<span class="tucao-reply-to">回复 @<?php echo esc_html($reply_to->comment_author); ?></span>
|
||||
<?php endif; ?>
|
||||
<span class="tucao-comment-time"><?php echo get_comment_date('Y-m-d H:i:s', $c); ?></span>
|
||||
</div>
|
||||
<div class="tucao-comment-text"><?php echo esc_html($c->comment_content); ?></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<div class="tucao-comment-form-wrap">
|
||||
<?php if (is_user_logged_in()) : ?>
|
||||
<form class="tucao-comment-form" method="post" action="<?php echo site_url('/wp-comments-post.php'); ?>">
|
||||
<input type="hidden" name="comment_post_ID" value="<?php the_ID(); ?>">
|
||||
<input type="hidden" name="comment_parent" value="0" class="tucao-reply-parent">
|
||||
<input type="text" name="comment" placeholder="说点什么..." required>
|
||||
<button type="submit">落笔</button>
|
||||
</form>
|
||||
<?php else : ?>
|
||||
<p class="tucao-login-hint"><a href="/wp-login.php">登录</a>后可留言</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
@@ -45,4 +61,9 @@ get_header();
|
||||
<p style="color:var(--ink-lighter);text-align:center;padding:60px 0;">暂无微言</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- 评论时间本地化脚本 -->
|
||||
<script>
|
||||
// 已改为 PHP 后端渲染,不需要 AJAX
|
||||
</script>
|
||||
|
||||
<?php get_footer(); ?>
|
||||
|
||||
Reference in New Issue
Block a user