I need this kind of pagination
with a small change
the pagination should never show more than 5 buttons/links ( not counting next/prev ) and if I am somewhere in mid of pagination it should show
1 ... 5 6 7 ... 20
or
1... 9 10 11 ... 20
if on last page
1... 17 18 19 20
I started with this
function pagination (){
// prev link
$html ='';
$numpages = 20;
$current_page = 1;
$dotshow = true;
if ($numpages != 1) {
$html .='<span><i class="fa fa-angle-left"></i></span>';// prev
for($i=1; $i <= $numpages; $i++){
if ($i == 1 || $i == $numpages || ($i >= $current_page - 3 && $i <= $current_page + 3) ) {
$dotshow = true;
if ($i != $current_page){
$html .='<a class="pagination-link" href="#linkhere">';
$html .='<span> '.$i.'</span>';
$html .='</a>';
}else{
$html .='<span class="current">';
$html .='<span> '.$i.'</span>';
$html .='</span>';
}
}else if ( $dotshow ){
$dotshow = false;
$html .='<span class="dots">';
$html .='<span> ... </span>';
$html .='</span>';
}
}
$html .='<span><i class="fa fa-angle-right"></i></span>';// next
}
if($html !=''){
return $html;
}
}
on first and last I get this
but on my page 5 it shows this and number of links increases because of the wrong current , total , limit calc.
any help is appreciated!