I want to build a page that would display all comments, regardless of which post they’re attached to. I also want that page to be paginated, since it’ll potentially have 10,000+ comments.
I’m not sure how to go about it, but here are some of the functions I’ve studied so far:
-
get_comments– If nopost_idis passed in, it’ll return all comments. However, I don’t see a way to paginate these (there areoffsetandnumberoptions to fiddle with, but that’s very tedious to do manually). -
wp_list_comments– The documentation on this is pretty bad, but the source code suggests that we can loop over all comments if used in conjunction withget_comments, by passing in theget_commentsarray as a second argument. This however would still useget_commentsto actually… well, get the comments, and there seems to be no way to paginate that. -
previous_comments_link&next_comments_link– These seem to only work in conjunction withwp_list_comments(with no second argument). -
paginate_comments_links– Also looks like it only works withwp_list_comments(with no second argument).
What I’ve tried:
-
Simply using the
numberargument inget_comments:$comments = get_comments(array( 'status' => 'approve', 'number' => '2' )); wp_list_comments(array( 'callback' => 'my_rendering_function' ), $comments); paginate_comments_links();This does not display any pagination links.
-
The method suggested here: Display latest comments on page with pagination
$comments = get_comments(array( 'status' => 'approve' )); wp_list_comments('per_page=2', $comments); paginate_comments_links();This doesn’t either work (it shows the first 2 comments, but no pagination). Also, I cringe at
get_commentsloading all comments into memory.
Question:
How can I paginate all comments?
P.S. I’m using WordPress 3.4.1 & PHP 5.3.2.
If your planning to build your own pagination, you will need to know the total number of comments your going to be using and thus your going to have to load all comments.
I’ve built below what i would use, let me know if it helps.