同类文档

typecho 楼层问题解决

https://yjvc.cn/index.php/archives/35/

文心一言代码

<?php
$floor = 1; // 初始化楼层为1

$db = Typecho_Db::get();
$sql = $db->select()

->from('table.comments')  
->where('cid = ?', $comments->cid)  
->where('status = ?', 'approved')  
->where('parent_id IS NULL') // 仅选择父评论  
->order('created', Typecho_Db::SORT_ASC);  

$result = $db->fetchAll($sql);

// 假设$comments是当前评论对象,并且您想要找到它之前的父评论数量
// 这里我们需要另一个查询来找到当前评论之前的父评论数量
$sqlCount = $db->select('COUNT(*) as count')

->from('table.comments')  
->where('cid = ?', $comments->cid)  
->where('status = ?', 'approved')  
->where('parent_id IS NULL')  
->where('created < ?', $comments->created) // 之前的父评论  
->limit(1);  

$resultCount = $db->fetchRow($sqlCount);

if ($resultCount && $resultCount['count'] > 0) {

$floor = $resultCount['count'] + 1; // 如果有之前的父评论,则楼层为之前的父评论数+1  

}

$floorText = $floor == 1 ? '1个脚印' : ($floor . '楼'); // 简化逻辑
?>

<?php echo '第' . $floorText; ?>  

更多文档