How to display comments in reverse order with pagination?
-
There is a need to implement a toggle button, that when it is pressed, the comments that were shown to the post, with pagination (from old to new) after its pressing were displayed from new to old (with the same pagination). In the documentation of wp_list_comments() there is a description of the ‘reverse_top_level’ parameter which is responsible for that. But in my case something goes wrong. Here is my code
<?php if (post_password_required()) { return; } $post_id = get_the_ID(); $per_page = 4; $comments_count = get_comments_number($post_id); if (isset($_GET['cpage']) && is_numeric($_GET['cpage'])) { $page = (int)$_GET['cpage']; } $page = max(1, $page); if ($GET_value_filter == 'newest') { /// In this parameter, I take away from the GET parameter of the page that this is sorting from new comments to old comments. function custom_default_comments_page2($value) { return 'newest'; } add_filter('pre_option_default_comments_page', 'custom_default_comments_page2'); $arg = array( 'type' => 'comment', 'reverse_top_level' => 1, 'callback' => 'reviews_theme_comment', 'per_page' => $per_page, 'number' => $per_page, 'cpage' => $page, ); wp_list_comments($arg); }
This is where 2 errors occur.
- I expect the first page of comments to show me 4 comments (‘per_page’ => 4), but for some reason it shows me only 2 *It should be clarified that when displaying comments from
old->new
it is indeed the last page with 2 comments. But here the first page should have 4 comments. - The last page of pagination contains the same set of comments as the first one, no matter how many comments are displayed per page….
I need to get comments for a custom post type, and these paginated comments should not conflict with the theme that users leave for posts. So I shouldn’t care what the site administrator sets in this set.
Can anyone have something useful to say about this problem?
- I expect the first page of comments to show me 4 comments (‘per_page’ => 4), but for some reason it shows me only 2 *It should be clarified that when displaying comments from
- The topic ‘How to display comments in reverse order with pagination?’ is closed to new replies.