Advertisement
lalatino

page menu

Aug 11th, 2012
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <!-- http://stackoverflow.com/questions/11917775/shorten-condense-number-of-pages-in-pagination -->
  2.  
  3.   <form action="" method="get">
  4.   <input name="page" type="text" value="" />
  5.   <input name="send" type="submit" value="send">
  6.   </form><br/>
  7.  
  8. <div id="user_nav_bottom">
  9. <?php
  10. $pages = array(30); for ($i=1;$i<=30;$i++) $pages[$i-1]='<p>page'.$i.'</p>';
  11. $current = $_GET['page'];
  12. $last = count($pages)+1;
  13. $curr0 = $current-2;
  14. $curr1 = $current+2;
  15. if ($curr0<=1) {
  16.   $curr0 = 1;
  17.   $curr1 = $last>5? 5 : $last;
  18. }
  19. if ($curr1>=$last) {
  20.   $curr0 = $last-4 < 1 ? 1 : $last-4;
  21.   $curr1 = $last;
  22. }
  23. // now print all links:
  24. echo '<a href="imgit_images.php?page=1">&#171;</a> ';
  25. for ($i=$curr0; $i<=$curr1; $i++) {
  26.   $style = ($i==$current)? 'font-weight:bold':'';
  27.   echo ' <a href="imgit_images.php?page='.$i.'" style="'.$style.'">'.$i.'</a> ';
  28. }
  29. echo '<a href="imgit_images.php?page='.$last.'">&#187;</a> ';
  30. ?>
  31. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement