pager.inc is... ugly. Let's get that out of the way. I'm sure there are valiant souls out there who are not bitching about it, but trying to fix it. I'm not one of those people right now, I've got my own battles, but if you happen to go up against it and want to create a pager for a data source which isn't a SQL database, here's what you need to do (mostly copied from pager_query):
Global variables (yes and it gets worse)
pager.inc makes extensive use of global variables to pass around the state of the pager. You can see how these are defined in pager_query():
global $pager_page_array, $pager_total, $pager_total_items;
Honestly, don't ask me what these are. Roughly, $pager_page_array is an array of different pagers on the page and what page they are at (I think). $pager_total is the total number of pages for each pager, $pager_total_items is the number of items in the set.
These are all set in pager_query if you care to find out more.
Getting the current page
You'll need this of course to split your set up so you can show just what you need to show on that page.
Fortunately, this is pretty straightforward in a really obtuse way:
$page = isset($_GET['page']) ? $_GET['page'] : ''; // The user will go to mypage?page=0,3,5,6. // What does this mean? There are 4 pagers on the page. // They don't have names, just numbers. // Sorta like in a prison, only it's a mental facility and the inmates are running it. // The first one is on page 0, the 2nd one on page 3, etc. etc $pager_page_array = explode(',', $page); // So this builds an array of all the pagers on the page and what page they are on. // One of these is the pager you care about. In most cases, it is the only one, // so you can just set $element = 0; $yourpage = $pager_page_array[$element];
Okay, now you do whatever you need to with that in terms of running a for loop to build a table or whatever.
Setting up the pager
// Number to show per page. $limit = 10; // The bizarre "element number" as long as you are the only pager on the page // this will work fine $element = 0; // $total_records is a variable you define that reflects the total number of // records you plan on showing (not per page but overall). $pager_total_items[$element] = $total_records // This is the total number of pages. If you can't figure this out, // go back to grammar school. $pager_total[$element] = ceil($pager_total_items[$element] / $limit); // wtf... $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1)); // No seriously... wtf... this is basically saying, I'm on the first page, // unless I'm not. I know, it's really clear.
Let it loose
return $my_paged_content . theme('pager'); // Go get a drink.
Okay, I hope I helped someone. Happy hacking.
Oh and don't forget to vote for my DrupalCon Copenhagen sessions!! I really want to go and got to get 'em accepted. If you want me to remind (harass) you when voting opens, please follow me on twitter @JacobSingh.