PHP Facebook Paginator
While building the Viddler Facebook application, I needed to create a pagination tool that worked just like Facebook’s. After looking at their HTML and their logic of what pages to display, I came up with one, which I’m releasing for anyone to use. The function takes 5 arguments, in the following order:
- $base_path: The base path for pagination. For instance, if /videos/4/ was page 4, $base_path would be “/videos”
- $cur_page: The current page number
- $total_items: The total number of items on the page
- $per_page: The number of items that are displayed on each page
- $footer_bar: If set to “true” this does not include the “Displaying items 1-5 of 10” text, and styles it as a footer paginator, instead of a header paginator.
- $name: What you’re paginating. This shows up as “Displaying $items 5-10 of 40”
Here’s an example:
<?php echo paginator('/videos', 2, 44, 5, false, 'items'); ?>
And here’s what it would look like:

You can download the source here. Hopefully this helps someone!

7 Comments
andi 21 Jul 2008 at 9:50AM
This is great, man. Thanks!
Vaibhav 09 Apr 2009 at 3:33PM
This is GREAT………… Thanks a lot!!!!!!!!
Kyle 09 Apr 2009 at 8:38PM
Glad I could help!
Andrew Slattery 14 Apr 2009 at 5:10PM
If it works like I hope it does (and as the screenshot depicts), I look forward to using it in my Facebook app! So thanks in advance!
Ram Khadka 02 May 2009 at 1:43AM
This is great. Thanks a lot
Lisa 19 May 2009 at 3:35PM
Augmented to work my way, but amazing starting point! Thanks much!
A.Hairi 14 May 2010 at 4:21PM
Thank you for sharing.
I am a still new to Facebook Application development and PHP. I am trying to show some items from an RSS feed inside my application tab using SimplePie. I was able to do so, but I wasn’t able to use your code in my case. Can you please elaborate more?
Thank you very much!