Guest User

Untitled

a guest
Jun 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. function pagination($rows, $perpage, $page=0, $offset, $base) {
  2. global $smarty;
  3.  
  4. $paging = array();
  5. $range = 7; // max number of items either side current page
  6.  
  7. $prev = '';
  8. $next = '';
  9.  
  10. $paging['current'] = $page;
  11. $paging['base'] = $base;
  12.  
  13. $pages = ceil($rows / $perpage);
  14. if ($page > 1) { $paging['prev'] = $page-1; }
  15. if ($page < $pages) { $paging['next'] = $page+1; }
  16.  
  17. $eitherside = $range * $perpage;
  18.  
  19. if($offset+1 > $eitherside) {
  20. $paging['leftrange'] = "... ";
  21. }
  22. if(($offset + $eitherside)<$rows) {
  23. $paging['rightrange'] = "... ";
  24. }
  25.  
  26. $pg = 1;
  27. for($y=0;$y<$rows;$y+=$perpage) {
  28. if(($y > ($offset - $eitherside)) && ($y < ($offset + $eitherside))) {
  29. $paging['pages'][] = $pg;
  30. }
  31. $pg++;
  32. }
  33.  
  34. $smarty->assign("paging", $paging);
  35. }
  36.  
  37.  
  38.  
  39. <div class="paging">
  40. {if $paging.prev}<a href="{$paging.base}&page={$paging.prev}">Previous</a> {/if}
  41. {$paging.leftrange}
  42. <span>
  43. {section name=page loop=$paging.pages}
  44. <a href="{$paging.base}&page={$paging.pages[page]}" {if $paging.current eq $paging.pages[page]}class="highlight"{/if}>{$paging.pages[page]}</a>
  45. {/section}
  46. </span>
  47. {$paging.rightrange}
  48. {if $paging.next}<a href="{$paging.base}&page={$paging.next}">Next</a>{/if}
  49. </div>
Add Comment
Please, Sign In to add comment