评论输出不完整怎么解决

讨论程序使用中的问题
回复
nenge
帖子: 1
注册时间: 2020年 12月 15日 15:21

评论输出不完整怎么解决

帖子 nenge »

一个三个评论,
一级的 显示
二级 显示
三级 找不到数据。
$comments->children 好像是一个纯数组,找不到它下一级的数据

代码: 全选

<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php

function ShowComments( $comments, $isChildren = false ) {
   $html = '';
   while ( $comments->next() ):
      $_comments = array(
         'cid' =>$comments->cid,
         'mail' =>$comments->mail,
         'url' =>$comments->url,
         'author' =>$comments->author,
         'created' =>$comments->created,
         'text' =>$comments->text
      );
      $html .= ShowCommentsHtml($_comments) ;
   if ( $comments->children ):
      foreach($comments->children  as $v){
         print_r($v);
         $html .= ShowCommentsHtml($v,array('author'=>$comments->author,'cid'=>$comments->cid));
      }
   endif;
   endwhile;
   return $html;
}
function ShowCommentsHtml($comments,$isChildren=false){
   return '<li id="comment-'.$comments['cid'].'" class="am-comment '.($isChildren ? 'am-comment-flip':'').'"><a href="#link-to-user-home"><img src="' .Typecho_Common::gravatarUrl( $comments['mail'], 48, 'X', 'mm', '' ) .'" alt="" class="am-comment-avatar" width="48" height="48"></a>' .'<div class="am-comment-main"><div class="am-comment-hd">' .'<div class="am-comment-meta"><a href="' . $comments['url'] . '" class="am-comment-author">' . $comments['author'] . '</a> ' .'评论于 <time datetime="' .date('c',$comments['created']). '">' . date('Y年m月d日 H:i:s',$comments['created']). '</time></div></div><div class="am-comment-bd">'.($isChildren?'<a href="#comment-'.$isChildren['cid'].'">@'.$isChildren['author'].'</a>':'').' ' . $comments['text'] . '</div></div></li>';
}
?>
    <?php $this->comments()->to($comments); ?>
    <?php if ($comments->have()): ?>
<ul class="am-comments-list am-comments-list-flip">
   <?php  echo  ShowComments($comments); ?>
回复