查看: 29|回复: 0

[技术教程] Typecho评论区增加楼层显示

[复制链接]
  • 打卡等级:常驻代表
  • 打卡总天数:47
  • 打卡月天数:1
  • 打卡总奖励:373
  • 最近打卡:2025-08-14 14:42:50
发表于 2025-7-21 14:58:15 | 显示全部楼层 |阅读模式
楼层初始化
  1. <?php
  2.     $floor = 1; // 初始化楼层为1

  3.     $db = Typecho_Db::get();
  4.     $sql = $db->select()
  5.         ->from('table.comments')
  6.         ->where('table.comments.cid = ?', $comments->cid)
  7.         ->where('table.comments.status = ?', 'approved')
  8.         ->order('table.comments.created', Typecho_Db::SORT_ASC);
  9.     $result = $db->fetchAll($sql);

  10.     foreach ($result as $row) {
  11.         if ($row['created'] < $comments->created) {
  12.             $floor++;
  13.         }
  14.     }

  15.     $floorText = $floor == 1 ? '1个脚印' : ($floor == 2 ? '2楼' : ($floor . '楼'));
  16.     ?>
  17.     <span class="reply joe_comment__reply" data-id="<?php $comments->theId(); ?>" data-coid="<?php $comments->coid(); ?>">
  18.         <?php echo '第' . $floorText; ?>
  19.     </span>
复制代码
  1. <span style="margin-left:5px;color:#617d0e;font-size:12px">
  2.     <?php if($comments->levels == 0): ?>
  3.     <?php if($comments->sequence == 1): ?>沙发
  4.     <?php elseif($comments->sequence == 2): ?>板凳
  5.     <?php elseif($comments->sequence == 3): ?>地毯
  6.     <?php else: ?>
  7.     第<?php  $comments->sequence(); ?>楼<?php endif; ?>
  8.     <?php endif; ?>
  9. </span>
  10. ...
复制代码
在主题目录下打开 comment.php 文件(参考路径:usr/themes/Joe/public/comment.php),在合适的位置(比如作者后面、或者是评论者后面都可以)添加以上代码。

原文地址:https://vjo.cc/35
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表