自定义评论为什么判断不出comment-child?

模板开发以及发布测试

版主: seita

回复
you6116
帖子: 9
注册时间: 2017年 10月 4日 22:21

自定义评论为什么判断不出comment-child?

帖子 you6116 »

按照官方的文档 http://docs.typecho.org/themes/custom-comments
comments.php里面添加

代码: 全选

<?php function threadedComments($comments, $options) {
    $commentClass = '';
    if ($comments->authorId) {
        if ($comments->authorId == $comments->ownerId) {
            $commentClass .= ' comment-by-author';  //如果是文章作者的评论添加 .comment-by-author 样式
        } else {
            $commentClass .= ' comment-by-user';  //如果是评论作者的添加 .comment-by-user 样式
        }
    }
    $commentLevelClass = $comments->_levels > 0 ? ' comment-child' : ' comment-parent';  //评论层数大于0为子级,否则是父级
?>

然后再把<li>改成

代码: 全选

<li id="li-<?php $comments->theId(); ?>" class="comment-body<?php 
if ($comments->_levels > 0) {
    echo ' comment-child';
    $comments->levelsAlt(' comment-level-odd', ' comment-level-even');
} else {
    echo ' comment-parent';
}
$comments->alt(' comment-odd', ' comment-even');
echo $commentClass;
?>">


就可以自动判断class了。如果是子评论会用comment-child。
但为什么我这样写了之后,class里还是comment-parent呢?
子评论和父评论都是comment-parent
是有什么问题吗?
求指导!谢谢。
回复