一级的 显示
二级 显示
三级 找不到数据。
$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); ?>