我想建立一个页面,显示所有评论,无论它们附加到哪个帖子。我还希望该页面分页,因为它可能会有10000多条评论。
我不知道该怎么做,但以下是我迄今为止研究过的一些函数:
get_comments
- 如果否post_id
传入,它将返回所有注释。然而,我看不到一种分页的方法(有offset
和number
可以随意选择,但手动操作非常繁琐)。wp_list_comments
- 这方面的文档很糟糕,但是the source code 建议如果与一起使用,我们可以循环查看所有注释get_comments
, 通过在get_comments
数组作为第二个参数。然而,这仍将使用get_comments
实际上。。。好吧,获取评论,似乎没有办法分页。previous_comments_link
&;next_comments_link
- 这些似乎只与wp_list_comments
(没有第二个参数)。paginate_comments_links
- 看起来它只适用于wp_list_comments
(没有第二个参数)。- 只需使用
number
中的参数get_comments
:
这不会显示任何分页链接。$comments = get_comments(array( \'status\' => \'approve\', \'number\' => \'2\' )); wp_list_comments(array( \'callback\' => \'my_rendering_function\' ), $comments); paginate_comments_links();
此处建议的方法:Display latest comments on page with pagination
这两者都不起作用(它显示前2条注释,但没有分页)。还有,我对$comments = get_comments(array( \'status\' => \'approve\' )); wp_list_comments(\'per_page=2\', $comments); paginate_comments_links();
get_comments
正在将所有注释加载到内存中。问题:我如何才能为所有评论分页?
<小时>P.S. 我正在使用WordPress 3.4.1;PHP 5.3.2。