您可以通过number
参数到get_comments()
仅检索特定数量的注释。按照标准,它们将按降序排列,因此您首先会得到最新的评论。
由于WordPress会自动将每篇文章的评论分开,所以您不必担心评论混淆。这对我来说似乎是最简单的方法。
Multiple comment forms per page -> Passing Post ID
如果在一个页面上需要多个评论表单,可以使用多个
get_comments()
, 但是您必须为要显示的评论传递帖子ID。
示例:
$postID = 4;
$number_of_posts = 6;
$args = array(
\'number\' => $number_of_posts,
\'post_id\' => $postID
);
$your_comments = get_comments($args);
Make it dynamic -> Extract IDs from post_meta and loop over them
帖子ID以逗号分隔保存在名为
commentIDs
, 代码将放置在
single.php
例如
// get IDs for current post
$cmmntIDs = get_post_meta($post->ID, \'commentIDs\', true);
$theIDs = explode(\',\', $cmmntIDs);
// get comments for each ID you defined
foreach($theIDs as $theID) {
$args = array(
\'number\' => $number_of_posts,
\'post_id\' => $theID
);
$comments = get_comments($args);
// basic output from the Codex Page on get_comments()
foreach($comments as $comment) {
echo($comment->comment_author);
}
}