Posted By

jamiebrwr on 08/13/10


Tagged

wordpress


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

jamalmohamed
joacoleo
pytheas
techdetours
neex123


Better Pagination


 / Published in: PHP
 

Place into fucntions.php

  1. /******* BETTER PAGINATION *********/
  2.  
  3. function pagination( $query, $baseURL ) {
  4. $page = $query->query_vars["paged"];
  5. if ( !$page ) $page = 1;
  6. $qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
  7. // Only necessary if there's more posts than posts-per-page
  8. if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
  9. echo '<ul class="paging">';
  10. // Previous link?
  11. if ( $page > 1 ) {
  12. echo '<li class="previous"><a href="'.$baseURL.'page/'.($page-1).'/'.$qs.'">&laquo; previous</a></li>';
  13. }
  14. // Loop through pages
  15. for ( $i=1; $i <= $query->max_num_pages; $i++ ) {
  16. // Current page or linked page?
  17. if ( $i == $page ) {
  18. echo '<li class="active">'.$i.'</li>';
  19. } else {
  20. echo '<li><a href="'.$baseURL.'page/'.$i.'/'.$qs.'">'.$i.'</a></li>';
  21. }
  22. }
  23. // Next link?
  24. if ( $page < $query->max_num_pages ) {
  25. echo '<li><a href="'.$baseURL.'page/'.($page+1).'/'.$qs.'">next &raquo;</a></li>';
  26. }
  27. echo '</ul>';
  28. }
  29. }

Report this snippet  

You need to login to post a comment.