Jump to content

Recommended Posts

Posted

Hello,

I've seen some code on the forum, but it doesn't seem to work for me, or I'm using it wrong.

I'm after a simple way to find out how many pages there are for a certain pagination, or the last page number.

Thanks.

Posted

This solution from diogo looks clean and logical:

https://processwire.com/talk/topic/1074-get-total-pages-pagination/?p=9411

What have you tried that didn't work?

You can also get the count of pages like this:

$num_pages = $pages->count("selector");

Then obviously divide this by the number of items you are displaying on each page and then ceil() the result.

Although this option would require a second query to the database, so go with the first option if you can.

  • Like 2
Posted (edited)

i usually do this:

$totalPages = ceil($total / $items_per_page);

edit: ah - just noticed adrian got there first...

Edited by Macrura
  • Like 1
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...