codebloo

Pagination in Functions.php

Dec 23rd, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /*-----------------------------------------------------------------------------------*/
  2. /* Pagination
  3. /*-----------------------------------------------------------------------------------*/
  4. function custom_pagination($numpages = '', $pagerange = '', $paged='') {
  5.  
  6. if (empty($pagerange)) {
  7. $pagerange = 2;
  8. }
  9.  
  10. /**
  11. * This first part of our function is a fallback
  12. * for custom pagination inside a regular loop that
  13. * uses the global $paged and global $wp_query variables.
  14. *
  15. * It's good because we can now override default pagination
  16. * in our theme, and use this function in default quries
  17. * and custom queries.
  18. */
  19. global $paged;
  20. if (empty($paged)) {
  21. $paged = 1;
  22. }
  23. if ($numpages == '') {
  24. global $wp_query;
  25. $numpages = $wp_query->max_num_pages;
  26. if(!$numpages) {
  27. $numpages = 1;
  28. }
  29. }
  30.  
  31. /**
  32. * We construct the pagination arguments to enter into our paginate_links
  33. * function.
  34. */
  35. $pagination_args = array(
  36. 'base' => get_pagenum_link(1) . '%_%',
  37. 'format' => 'page/%#%',
  38. 'total' => $numpages,
  39. 'current' => $paged,
  40. 'show_all' => False,
  41. 'end_size' => 1,
  42. 'mid_size' => $pagerange,
  43. 'prev_next' => True,
  44. 'prev_text' => __('«'),
  45. 'next_text' => __('»'),
  46. 'type' => 'plain',
  47. 'add_args' => false,
  48. 'add_fragment' => ''
  49. );
  50.  
  51. $paginate_links = paginate_links($pagination_args);
  52.  
  53. if ($paginate_links) {
  54. echo "<section class='custom-pagination pagination'>";
  55. echo $paginate_links;
  56. echo "</section>";
  57. }
  58.  
  59. }
Add Comment
Please, Sign In to add comment