Simple pagination system in your WordPress plugins
May be you are developing a plugin or a theme and it has something to do with handing some pagination of your custom tables data. Here’s how we can simply manage it, I am not going to build all the admin panel stuffs, but just showing you the process.
Step 1:
Lets get the page number from the url query string. If we don’t find anything, we’ll set the page number to 1.
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
Step 2:
Now we need to set per page entry limit and the page offset. We will use the limit and offset to get data from our MySQL query. If you are confused about the offset, may be you’ve seen it on PHPMyAdmin like this: "SELECT * FROM `table_name` LIMIT 0, 10". Here, we are getting the first 10 entries from our database. If we want get the next 10 entries, our limit will be "LIMIT 10, 10". So the first digit for the limit is the offset. It tells us from where we’ll get our next entries.
$limit = 10; $offset = ( $pagenum - 1 ) * $limit;
So, by this two lines we are setting the limit and our offset dynamically. Read the rest of this entry »








