Skip Navigation

[Resolved] Next and previous pagintion with number of of posts?

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to show the number of posts along with the Next and Previous page buttons in my pagination.

Solution: Add a custom shortcode like so:

add_shortcode( 'custom_page_results_count', 'custom_page_results_count_func');
function custom_page_results_count_func($atts)
{
  $direction = intval($atts['direction']);
  $numresults = $atts['numresults'];
  $currentpage = $atts['currentpage'];
  $postsperpage = $atts['postsperpage'];
  $numberofpages = $atts['numpages'];
  if($currentpage + $direction == $numberofpages) {
    $mod = $numresults % $postsperpage;
    return $mod ? $mod : $postsperpage;
  }
  return $postsperpage;
}

Then in your Filter editor, place your custom shortcode like so for Previous results:

[wpml-string context="wpv-views"]Previous [custom_page_results_count direction="-1" numresults="[wpv-found-count]" currentpage="[wpv-pager-current-page]" postsperpage="5" numpages="[wpv-pager-total-pages]"] Results[/wpml-string]

Replace the postsperpage value with the number of posts per page as found in your View's pagination settings. Note the direction "-1" for previous results - we'll use "1" for next results.

Then you can place the same custom shortcode with direction="1" like so for Next results:

[wpml-string context="wpv-views"]Next [custom_page_results_count direction="1" numresults="[wpv-found-count]" currentpage="[wpv-pager-current-page]" postsperpage="5" numpages="[wpv-pager-total-pages]"] Results[/wpml-string]

Again, replace the postsperpage value with the number of posts per page.

Relevant Documentation: https://toolset.com/documentation/toolset-training-course/part-4-pagination/

This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by bobA-2 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#516238

Is it possible to have the number of posts shown with Next and Previous Pagination Controls?

So I want pagination to show Next X posts where X is the value of posts to be shown.

Of course I could write the pagination size like 15 in the code after [wpv-pager-next-page] but that would not always be correct if there are less than 15 items in the last pagination.

#516268

Hi, this isn't currently possible with Toolset but I think you may be able to use a custom shortcode. Please add the following code to functions.php:

add_shortcode( 'custom_page_results_count', 'custom_page_results_count_func');
function custom_page_results_count_func($atts)
{
  $direction = intval($atts['direction']);
  $numresults = $atts['numresults'];
  $currentpage = $atts['currentpage'];
  $postsperpage = $atts['postsperpage'];
  $numberofpages = $atts['numpages'];
  if($currentpage + $direction == $numberofpages) {
    $mod = $numresults % $postsperpage;
    return $mod ? $mod : $postsperpage;
  }
  return $postsperpage;
}

Then in your Filter editor, place your custom shortcode like so for Previous results:

[wpml-string context="wpv-views"]Previous [custom_page_results_count direction="-1" numresults="[wpv-found-count]" currentpage="[wpv-pager-current-page]" postsperpage="5" numpages="[wpv-pager-total-pages]"] Results[/wpml-string]

Replace the postsperpage value with the number of posts per page as found in your View's pagination settings.

Note the direction "-1" for previous results - we'll use "1" for next results.

Then you can place the same custom shortcode with direction="1" like so for Next results:

[wpml-string context="wpv-views"]Next [custom_page_results_count direction="1" numresults="[wpv-found-count]" currentpage="[wpv-pager-current-page]" postsperpage="5" numpages="[wpv-pager-total-pages]"] Results[/wpml-string]

Again, replace the postsperpage value with the number of posts per page.

#516389

Cool that works 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.