I have custom PHP site and using this script for pagination.
echo "Page <strong>$pagenum</strong> of <strong>$last</strong><br><br>";
if ($pagenum == 1)
{
}
else
{
echo "<li> <a href='{$_SERVER['PHP_SELF']}?pagenum=1'><strong>First page</strong></a></li>";
echo " ";
$previous = $pagenum-1;
echo "<li> <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>".$previous."</a></li>";
}
echo "";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " .... <li><a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> ".$next."</a></li>";
echo " ";
echo "<li><a href='{$_SERVER['PHP_SELF']}?pagenum=$last'><strong>Last page</strong></a></li>";
}
This only shows last two pages, not even first page. How to customize it to display first 5 and last 5 pages.
It all depends on where and how your pages are stored though! if you do that with a database, you would need to check if the $pagenum ( which we don’t see defined anywhere ) has previous/next pages… and based on that you draw you +/- 5 pages anchors! preferably doing some looping!
On the other hand if you are not using any database and just want to show some content based on the ?pagenum=(number) which is what you seem to do here! you would need to get the current page via $_GET[‘pagenum’] once the user is on the new page! so that the content displays properly!
well then you simply do something like :
if that “method” is too basic to you have a look at this ones simple-php-mysql-pagination, how-to-paginate-data-with-php, basic-pagination