id summary reporter owner description type status priority milestone component version severity resolution keywords cc 3201 Pagination for threaded comments MBV "It would be really great if pagination for threaded comments could be looked into again. I notice there are a lot of people wanting this feature. @svetoslavd79 came up with a mostly working solution [https://wpup.co/bbpress-threaded-nested-replies-with-paging/] and in the comments section suggested an idea/consideration on how it could be re-done more elegantly to prevent url linking issues: > ...I’m starting to think that the most elegant way to deal with all this issues surrounding pagination of replies is to create a hidden field in the reply form that saves the page number as a custom field attached to the reply. If you can accomplish that, modifying or filtering anything that needs a link to that particular reply post should be a breeze after that. Anything else will have to involve some wild math to calculate each reply page number and will only weigh in on the execution and ultimately site speed and performance. This is still not super simple but something to consider if you want to pursue such implementation. Nevertheless, the code outlined below seems to work well with standard bbpress forum, with a couple of issues: 1. There is an issue with a buddypress group forum: after posting reply there, the refreshed url page number is incorrect. 2. When trashing a reply in forum, the pagination breaks... redirect goes to something like this .../?view=all#post-4296 and the pagination does not work and can't navigate pages as their url links are no longer correct. 3. Links may not link to the correct page number for the topic subscription email notifications and the Recent Replies widget. Below is the extract of @svetoslavd79 code from [https://wpup.co/bbpress-threaded-nested-replies-with-paging/] Copy the below function to your functions.php file. The modification will allow us to pass the current page and number of replies per page, so the query returns the correct reply posts. {{{ function wpup_bbp_list_replies( $args = array() ) { // Reset the reply depth bbpress()->reply_query->reply_depth = 0; // In reply loop bbpress()->reply_query->in_the_loop = true; $r = bbp_parse_args( $args, array( 'walker' => null, 'max_depth' => bbp_thread_replies_depth(), 'style' => 'ul', 'callback' => null, 'end_callback' => null ), 'list_replies' ); // Get replies to loop through in $_replies $walker = new BBP_Walker_Reply; $walker->paged_walk( bbpress()->reply_query->posts, $r['max_depth'], $r['page'], $r['per_page'], $r ); bbpress()->max_num_pages = $walker->max_pages; bbpress()->reply_query->in_the_loop = false; } }}} Next copy the below function to your functions.php file, right after the previous one from Step 1. This piece of code is responsible for displaying the page number navigation. The 2 important variables here are $numeplies – the total number of replies of the currently displayed topic and $paged – the current page number the visitor is displaying. You will find out how we are going to pass those values in the next few steps. {{{ //Custom Pagination function function wpup_custom_pagination($numreplies='', $pagerange='', $paged='', $repliesperpage='') { /** * $pagerange * How many pages to display after the current page * Used in combination with 'shaw_all' => false */ if (empty($pagerange)) { $pagerange = 3; } /** * $numreplies * What is the total number of replies in the current topic * $numpages * Calculate total number of pages to display based on number of replies and replies per page */ if ($numreplies != '') { $numpages = ceil($numreplies / $repliesperpage); } //assign value of 1 to $paged variable in case it's not passed on global $paged; if (empty($paged)) { $paged = 1; } /** * We construct the pagination arguments to enter into our paginate_links * function. */ $pagination_args = array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'total' => $numpages, 'current' => $paged, 'show_all' => False, 'end_size' => 1, 'mid_size' => $pagerange, 'prev_next' => True, 'prev_text' => __('<'), 'next_text' => __('>'), 'type' => 'plain', 'add_args' => false, 'add_fragment' => '' ); $paginate_links = paginate_links($pagination_args); if ($paginate_links) { echo """"; } } }}} This next snippet takes the current page you are on and changes the value of the hidden field in the reply form. This is so after replying, the page doesn't load at page 1. {{{ //customize the forum reply form redirect to send back to the current page you are on function wpup_reply_redirect() { if (bbp_is_single_topic()) { $redirect_to = ''; } return $redirect_to; } add_filter('bbp_redirect_to_field', 'wpup_reply_redirect', 10, 2); }}} However, two other places that may need looking at where the links may not link to the correct page number are the topic subscription email notifications and the Recent Replies widget. Next, edit loop-replies.php. On top of the file and right after the opening }}} and replace it with {{{ $paged, 'per_page' => 15)); ?> }}} *Remember to change 15 with the number of replies you want to see per page. Also, please note that only the main replies are considered when specifying the number per page, since the nested replies are children of the main reply. Next we want to call our pagination function, to display the page navigation. To do that, scroll down to around line 84 and include the following, right after the closing tag: {{{
reply_query->posts; $numparentreplies = 0; foreach($replyposts as $value){ if($value->reply_to == 0) { $numparentreplies++; } } wpup_custom_pagination($numparentreplies,"""",$paged, 15); ?>
}}} " enhancement new normal Future Release Component - Replies normal wpdennis