我的很多方法都是基于这个线程的here
我目前可以在作者模板页面上显示5条最新评论。我想显示任何用户对每个“主要”评论的最新3条回复(因此父项=0)
我可以通过print\\r识别回复,但使用例如get\\u comment\\u link作为comment\\u id是完全不显示的,无法识别回复。
这是代码。
<?php $args = array(
\'user_id\' => $curauth->ID,
\'number\' => 5,
\'status\' => \'approve\',
\'parent\' => 0
);
$comments = get_comments($args);
if ( $comments )
{
foreach($comments as $c){
echo \'<ul id="authorcomments">\';
echo \'<li>\';
echo \'<a id="authorcommentlink" href="\'.get_comment_link( $c->comment_ID ).\'"> \';
echo get_the_title($c->comment_post_ID);
echo \'</a>\';
echo "</br> <div id=\'authorcommentexcerpt\'>" . get_comment_excerpt( $c->comment_ID );
echo "</div></li>\\n";
echo \'</ul>\';
$parent_comment_id = $c->comment_ID;
$comment_meta_args = array(
\'status\' => \'approve\',
\'parent\' => intval($parent_comment_id),
\'number\' => 3
);
$replies = get_comments($comment_meta_args);
echo \'<ul id="authorcomments">\';
echo \'<li>\';
echo \'<a id="authorcommentlink" href="\'.get_comment_link( $replies->comment_ID ).\'"> \';
echo get_the_title($replies->comment_post_ID);
echo \'</a>\';
echo "</br> <div id=\'authorcommentexcerpt\'>" . get_comment_excerpt( $replies->comment_ID );
echo "</div></li>\\n";
echo \'</ul>\';
}
} else { echo "<p style=\'text-align: center\'> Nothing! </p>\\n";} ?>
SO网友:tim daniels
我的错。还应该为回复添加foreach。
<?php $args = array(
\'user_id\' => $curauth->ID,
\'number\' => 5,
\'status\' => \'approve\',
\'parent\' => 0
);
$comments = get_comments($args);
if ( $comments )
{
foreach($comments as $c){
echo \'<ul id="authorcomments">\';
echo \'<li>\';
echo \'<a id="authorcommentlink" href="\'.get_comment_link( $c->comment_ID ).\'"> \';
echo get_the_title($c->comment_post_ID);
echo \'</a>\';
echo "</br> <div id=\'authorcommentexcerpt\'>" . get_comment_excerpt( $c->comment_ID );
echo "</div></li>\\n";
echo \'</ul>\';
$parent_comment_id = $c->comment_ID;
$comment_meta_args = array(
\'status\' => \'approve\',
\'parent\' => intval($parent_comment_id),
\'number\' => 3
);
$replies = get_comments($comment_meta_args);
foreach($replies as $r) {
echo \'<ul id="authorcomments2">\';
echo \'<li>\';
echo \'<a id="authorcommentlink2" href="\'.get_comment_link( $r->comment_ID ).\'"> \';
echo get_the_title($r->comment_post_ID);
echo \'</a>\';
echo "</br> <div id=\'authorcommentexcerpt2\'>" . get_comment_excerpt( $r->comment_ID );
echo "</div></li>\\n";
echo \'</ul>\';
}
}
} else { echo "<p style=\'text-align: center\'> Nothing! </p>\\n";} ?>