This pagination script was designed with modularity in mind. It is extremely easy to add it all over your website without editing any code whatsoever.
To begin, upload all the files and folders located in the “uploads” directory to your site’s main directory or the directory you wish to use pagination.
In your html head tags, add this code snippet:
<link href="PATH/TO/pagination.css" rel="stylesheet" type="text/css" media="screen" />
Make sure you replace the “PATH/TO” to the path where the pagination.css is actually located.
Once the files are uploaded, include this code snippet in the file you wish to use pagination:
define("IN_PAGI", true);
require("PATH/TO/class_pagination.php");
//grab the current page
$page = intval($_GET['page']);
//set the page if empty
if(empty($page))
{
$page = 1;
}
Make sure to change the PATH/TO/ to the actual path location the class_pagination.php file is located.
The above code snippet defines IN_PAGI so the pagination class can run, then we include the pagination
class. The variable page grabs the current page; no need to worry about the URL’s yourself, the .tpl file takes care of that for you. The if control structure checks if the variable page is empty, and sets the
default page, nothing to worry about there.
Next, add this code snippet above where your query to paginate the data (do not grab the data from the query, this is only used to grab the total number of rows returned, read below):
$pagination = new Pagination($limit, $rows, $page, $location);
After instantiating the class, the first parameter takes how many results you want per page.
The second parameter takes the total amount of rows that are pulled out. If you are using MySQL, you run your select query, then a mysql_num_rows function to select the total rows your query grabbed.
That total should be placed in the second parameter.
The third parameter is your current page, leave that set to the $page variable as that is what we used
earlier.
The fourth and last parameter is your current location. In other words, the URL of where you are at WITHOUT a trailing slash. This is used to append the current page to the URL when the pagination runs.
For example, your location could be:
http://yoursite.com/index.php?action=wallpapers
OR
http://yoursite.com/index.php
If it is the first example we used, make sure you add this &page to the end of it as shown below:
http://yoursite...p;amp;page
If it is the second example used, add this ?page to the end of it as shown below:
http://yoursite.com/index.php?page
Now this URL would be the location parameter, the pagination script would do the rest.
Now add this code snippet right before you run your actual query, remember, the other query was just
to grab the total rows, and not to delimit how many rows to display:
$start = $pagination->prePagination();
If you’re using MySQL, add this code snippet to the end of your SQL query:
LIMIT $start, 12
This will set the limit and what data to pull out. Change the number 12 to the number you set on how many rows you want per page.
Now for the final step, add this code snippet to where you want the pagination to appear (make sure
it’s under all the code we just added):
$pagination->pagination();
Success!
You now have your pagination running, follow the same steps except the uploading steps to add the pagination to other parts of your site. If you want to modify the tpl file, read below to learn its
functionalities