58ef5f2635
微言评论: - 需登录后留言,未登录提示 - PHP 后端渲染评论,本地证件照头像 - 平级评论 + @回复引用 - 时间线 ASC 排列 - 评论无需审核直接显示 - tucao 禁用单独详情页 - 评论后锚点定位回列表 Photo 画廊: - 灯箱全屏查看,多图左右切换 - 单图/边界隐藏方向键 - 图片去重 - 顶部显示标题·作者
70 lines
3.6 KiB
PHP
70 lines
3.6 KiB
PHP
<?php
|
||
/**
|
||
* 微言归档页 — 带 AJAX 评论 + 登录验证
|
||
*/
|
||
get_header();
|
||
?>
|
||
|
||
<div class="section-header">
|
||
<span class="section-title">💬 微言</span>
|
||
<span class="section-filter" style="font-size:13px;color:var(--ink-lighter);">片语只言,皆是存在</span>
|
||
</div>
|
||
|
||
<?php if (have_posts()) : ?>
|
||
<?php while (have_posts()) : the_post(); ?>
|
||
<div class="tucao-item" id="tucao-<?php the_ID(); ?>">
|
||
<div class="tucao-header">
|
||
<?php echo get_avatar(get_the_author_meta('ID'), 16, '', '', array('class' => 'tucao-avatar')); ?>
|
||
<span class="tucao-author"><?php the_author_meta('display_name'); ?></span>
|
||
<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="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', 'order' => 'ASC'));
|
||
foreach ($comments as $c) :
|
||
$reply_to = $c->comment_parent ? get_comment($c->comment_parent) : null;
|
||
?>
|
||
<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; ?>
|
||
<nav class="pagination">
|
||
<?php echo paginate_links(array('prev_text' => '‹', 'next_text' => '›')); ?>
|
||
</nav>
|
||
<?php else : ?>
|
||
<p style="color:var(--ink-lighter);text-align:center;padding:60px 0;">暂无微言</p>
|
||
<?php endif; ?>
|
||
|
||
<!-- 评论时间本地化脚本 -->
|
||
<script>
|
||
// 已改为 PHP 后端渲染,不需要 AJAX
|
||
</script>
|
||
|
||
<?php get_footer(); ?>
|