Paged Navigation – My own way

Recently while working for a wordpress plugin, though there are a lot of solutions for this, I could not find the exact thing which I needed, and thought about writing one of my own. Just writing it and using in the current project would be a waste, so thought I would slap it on here. It would help me in the long run..

First, where we want to have the pagination select the count of items we have to paginate.

SELECT count(*) FROM <tablename> where <condition>

Then make sure there is a page request variable. Even if the paged requests have not started, assume we are on the first page.

if ( !isset( $_GET['paged'] ) )
$_GET['paged'] = 1;

Use the page request information in your data query to limit the data rows.

SELECT * FROM <tablename> where <condition> limit {(($_GET['paged'] - 1) * <per_page>)},<per_page>

Invoke the function shown at the end,

mkPageLinks( ceil( <count> / <perpage> ), $_GET['paged'] );

I lost the formatting, when I tried editing the post using scribe fire.. So will just update the downloadable file..

TODO
This could be made generic by defining the page links span, and a lot of other tweaks.. but when using in wordpress admin page, try to use class=”page-numbers” on the paged links, and class=”prev/next page-numbers” on the previous/next links, and class=”page-numbers current” on the span tag.. which will use the wp admin css.

For convinence the function code is added as plain text to the downloads list.. Download