I wrote a simple, yet extremely useful WordPress pagination class. The class is not complete yet, and I work on it as I move along and need new features or actions. So you have the freedom to take the class and customize/expand it as you might need to. First off, you can download the class below :
WordPress Pagination Class
In order to use the class, you’ll need to include the class file. With the class file included, you can initialize the class and then execute the startPaging() class method. Before you execute the method, you need to specify some variable values. See the example below :
include_once(ABSPATH . 'wp-content/plugins/yourplugin/class.pagination.php');
$tableName = $wpdb -> prefix . 'yourplugintable';
$tableFields = '`id`, `title`, `description`';
$pagination = new Pagination($tableName, $tableFields);
$pagination -> perPage = 10;
$pagination -> pluginUrl = '?page=yourplugin.php&';
$allRecords = $pagination -> startPaging($_GET['wpMailinglistPage']);
From there, you can simply loop through your records with a foreach(); or something similar to output the records. In order to output the page numbers/links and the “previous”/”next” links, you can echo the pagination(); class method. See the example below :
= $pagination -> pagination(); ?>
Good luck! I hope this is useful!
Please feel free to post your updated source code, ideas and comments.