Posted By

Znupi on 08/20/09


Tagged

php pagination


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

profpatsy


Pagination


 / Published in: Smarty
 

URL: http://it-ride.blogspot.com/2009/08/pagination-with-smarty.html

Visit the URL above for an explanation on how to use this and how it works.

  1. {assign var="putDots" value=3}
  2. {assign var="border" value=2}
  3.  
  4. {assign var="curPage" value=$pagination.curPage}
  5. {assign var="url" value=$pagination.url}
  6. {assign var="totalPages" value=$pagination.totalPages}
  7. {if $totalPages > 1}
  8. <div class="pages">
  9. <span>
  10. {if $curPage > 1}
  11. <a title="Previous Page" href="{$url|replace:'%x':$curPage-1}">&laquo;&laquo;</a>
  12. {/if}
  13.  
  14. {* Handle the first part of the pages -- up to the current one *}
  15. {if $curPage > $putDots}
  16. <a title="Page 1" href="{$url|replace:'%x':'1'}">1</a>
  17. ...
  18. {section name=i start=$curPage-$border loop=$curPage}
  19. {assign var="curPos" value=$smarty.section.i.index}
  20. <a title="Page {$curPos}" href="{$url|replace:'%x':$curPos}">{$curPos}</a>
  21. {/section}
  22. {else}
  23. {section name=i start=1 loop=$curPage}
  24. {assign var="curPos" value=$smarty.section.i.index}
  25. <a title="Page {$curPos}" href="{$url|replace:'%x':$curPos}">{$curPos}</a>
  26. {/section}
  27. {/if}
  28.  
  29. {* Current page *}
  30. <a title="Page {$curPage}" class="current" href="{$url|replace:'%x':$curPage}">{$curPage}</a>
  31.  
  32. {* Handle the last part of the pages -- from the current one to the end *}
  33. {if $totalPages - $curPage + 1 > $putDots}
  34. {section name=i start=$curPage+1 loop=$curPage+$border+1}
  35. {assign var="curPos" value=$smarty.section.i.index}
  36. <a title="Page {$curPos}" href="{$url|replace:'%x':$curPos}">{$curPos}</a>
  37. {/section}
  38. ...
  39. <a title="Page {$totalPages}" href="{$url|replace:'%x':$totalPages}">{$totalPages}</a>
  40. {else}
  41. {section name=i start=$curPage+1 loop=$totalPages+1}
  42. {assign var="curPos" value=$smarty.section.i.index}
  43. <a title="Page {$curPos}" href="{$url|replace:'%x':$curPos}">{$curPos}</a>
  44. {/section}
  45. {/if}
  46.  
  47. {if $curPage < $totalPages}
  48. <a title="Next Page" href="{$url|replace:'%x':$curPage+1}">&raquo;&raquo;</a>
  49. {/if}
  50. </span>
  51. </div>
  52. {/if}

Report this snippet  

You need to login to post a comment.