ThLoser Posted June 25, 2013 Share Posted June 25, 2013 I have a paging script right now, and i want to only show 5 sites like this 1 2 3 4 5 2 3 4 5 6 And so on. I have 9 pages right now, and when i come to page 6-7 the script removes everything backward but i want it to be 5 6 7 8 9 function pager($link, $page, $pages, $sub='') { $PageLink = '<div class="pagination pagination-mini"><ul>'; if($page != 1) $PageLink .= '<li><a href="'.$link.'&page='.($page-1).'" rel="nofollow">«</a></li>'; if($page+4 >= $pages) $pagex=$pages; else $pagex = (($page != 5) ? $page+4 : $page+1); echo $page-4; for($i=$page-4 ; $i<=$pagex ; $i++) { if($i<=0) $i=1; if($i==$page) $PageLink .= '<li><a href="#" style="font-weight:bold;" rel="nofollow">'.$i.'</a></li>'; else $PageLink .= '<li><a href="'.$link.'&page='.$i.'" rel="nofollow">'.$i.'</a></li>'; } if($page != $pages) $PageLink .= '<li><a href="'.$link.'&'.$sub.'page='.($page+1).'" rel="nofollow">»</a></li>'; $PageLink .= '</div>'; return $PageLink; } I can try to explain better if necessary Quote Link to comment Share on other sites More sharing options...
sasa Posted August 1, 2013 Share Posted August 1, 2013 he in your code try to replace if($page+4 >= $pages) $pagex=$pages; else $pagex = (($page != 5) ? $page+4 : $page+1); echo $page-4; for($i=$page-4 ; $i<=$pagex ; $i++) { with if($page+2 >= $pages) $pagex=$pages; else $pagex = $page+2); if($page > $pagex - 2) $pagein = $pagex - 4; else $pagein = $page - 2; if($pagein < 1) $pagein = 1; for($i = $pagein; $i <= $pagex; $i++) { Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.