Notebook

July 08, 2008 11:47PM

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:

Paginator example

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

Did you like this entry? Make sure to subscribe to my RSS feed to keep up-to-date with my newest entries and links.

Comments

Avatar

andi

July 21, 2008 at 9:50AM #

This is great, man. Thanks!

Leave a Comment

(required)

(required, never displayed)

(optional)

Ajax-loader

About

This entry was published on July 08, 2008. 1 response has been posted.

Tags: , , , ,

Links

Important links from within the post.