Alles gaat goed totdat er meerdere pagina's komen en er pagina's worden weggelaten.
<?php
function paginate($limiet, $pagina, $total_pages, $html)
{
// Initial page num setup
if($pagina == 0)
{
$pagina = 1;
}
$prev = $pagina - 1;
$next = $pagina + 1;
$lastpage = ceil($total_pages/$limiet);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= '<div class="paginate">';
// Previous
if ($pagina > 1)
{
$paginate .= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$prev.'"> Vorige</a>';
}
else
{
$paginate.= '<span class="disabled"> Vorige </span>';
}
$stages = "";
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $pagina)
{
$paginate .= '<span class="current">'.$counter.'</span>';
}
else
{
$paginate .= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$counter.'"> '.$counter .'</a>';
}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($pagina < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $pagina)
{
$paginate.= '<span class="current"> '.$counter.' </span>';
}
else
{
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$counter.'"> '.$counter.' </a>';
}
}
$paginate.= '...';
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$LastPagem1.'"> '.$LastPagem1.' </a>';
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$LastPagem1.'"> '.$lastpage.' </a>';
}
elseif($lastpage - ($stages * 2) > $pagina && $pagina > ($stages * 2))
{
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page=1"> 1 </a>';
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page=2"> 2 </a>';
$paginate.= '...';
for ($counter = $pagina - $stages; $counter <= $pagina + $stages; $counter++)
{
if ($counter == $pagina)
{
$paginate.= '<span class="current"> '.$counter.' </span>';
}
else
{
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$counter.'"> '.$counter .'</a>';
}
}
$paginate.= '...';
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$LastPagem1.'"> '.$LastPagem1.' </a>';
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$lastpage.'"> '.$lastpage.' </a>';
}
else
{
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page=1"> 1</a>';
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page=2"> 2</a>';
$paginate.= '...';
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $pagina)
{
$paginate.= '<span class="current"> '.$counter.' </span>';
}
else
{
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$counter.'"> '.$counter.' </a>';
}
}
}
}
// Next
if ($pagina < $counter - 1)
{
$paginate.= '<a href="'.$html.'?id='.$_GET['id'].'&page='.$next.'"> Volgende</a>';
}
else
{
$paginate.= '<span class="disabled"> Volgende</span>';
}
$paginate.= '</div>';
}
return $paginate;
}
?>