php - Display ... in pagination -
i have pagination issue. pagination work fine. want display started 3 page after want display (....) , @ last point want display last page. here code:
<?php $videocount= 1000; $page = (!isset($_get['page']))? 1 : $_get['page']; $prev = ($page - 1); $next = ($page + 1); /* max results per page */ $max_results = 50; /* calculate offset */ $from = (($page * $max_results) - $max_results); $last = $from + $max_results; /* query api total results.*/ //$total=107; $total_results = $videocount; $total_pages = ceil($total_results / $max_results); if($page==$total_pages ){ $last=$total_results ; }else{ $last=$last; } $pagination = ''; /* create prev link if there 1 */ if($page > 1) { $pagination.= '<li> <a href="?&page='.$prev.'"> <span class="prevbtn"><i class="fa fa-caret-left"></i> previous</span> </a></li>'; } /* loop through total pages */ //for($i = 1; $i <= $total_pages; $i++) before meeting code for($i = 1; $i <= $total_pages; $i++) { if(($page) == $i) { //$pagination .= $i; $pagination .= '<li> <a href="#"> <span>'.$i.' </span> </a></li>'; //implement active class here } else { $pagination .= '<li> <a href="?page='.$i.'"> <span> '.$i.' </span> </a></li>'; } } if($page < $total_pages) { $pagination.= '<li> <a href="?page='.$next.'"> <span class="nextbtn"> next <i class="fa fa-caret-right"></i> </span> </a></li>'; } ?>
thanks,
i have added if...else statement inside loop in code. might you
<?php $videocount= 1000; $page = (!isset($_get['page']))? 1 : $_get['page']; $prev = ($page - 1); $next = ($page + 1); /* max results per page */ $max_results = 50; /* calculate offset */ $from = (($page * $max_results) - $max_results); $last=$from + $max_results; /* query api total results.*/ //$total=107; $total_results = $videocount; $total_pages = ceil($total_results / $max_results); if($page==$total_pages ) { $last=$total_results ; } else { $last=$last; } $pagination = ''; /* create prev link if there 1 */ if($page > 1) { $pagination.= '<li> <a href="?&page='.$prev.'"> <span class="prevbtn"><i class="fa fa-caret-left"></i> previous</span> </a></li>'; } /* loop through total pages */ //for($i = 1; $i <= $total_pages; $i++) before meeting code for($i = 1; $i <= $total_pages; $i++) { if(($page) == $i) { //$pagination .= $i; $pagination .= '<li> <a href="#"> <span>'.$i.' </span> </a></li>'; //implement active class here } else { //display first 3 pages if($i<=3) $pagination .= '<li> <a href="?page='.$i.'"> <span> '.$i.' </span> </a></li>'; //display last 3 pages else if($total_pages-$i<3) $pagination .= '<li> <a href="?page='.$i.'"> <span> '.$i.' </span> </a></li>'; else { if($total_pages-$i<=6) $pagination .= '<li> <a href="?page='.$i.'"> <span> . </span> </a></li>'; } } } if($page < $total_pages) { $pagination.= '<li> <a href="?page='.$next.'"> <span class="nextbtn"> next <i class="fa fa-caret-right"></i> </span> </a></li>'; } echo $pagination; ?>
Comments
Post a Comment