job-pagination.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Pagination - Show numbered pagination for jobs
  4. *
  5. * @author PressTigers
  6. * @package Simple_Job_Board
  7. * @subpackage Simple_Job_Board/templates/listing
  8. * @version 1.0.0
  9. * @since 2.2.0
  10. * @since 2.4.0 Revised Pagination HTML Structure
  11. */
  12. ob_start();
  13. global $wp_rewrite;
  14. // Get Shortcode Attributes
  15. $job_query = empty( $job_query ) ? '' : $job_query;
  16. /**
  17. * Job listing pagination
  18. *
  19. * Show pagiantion after displaying
  20. */
  21. $job_query->query_vars['paged'] > 1 ? $current = $job_query->query_vars['paged'] : $current = 1;
  22. // Pagination Arguments
  23. $pagination_args = array(
  24. 'base' => @add_query_arg('page', '%#%'),
  25. 'format' => '?paged=%#%',
  26. 'total' => $job_query->max_num_pages,
  27. 'current' => $current,
  28. 'show_all' => FALSE,
  29. 'next_text' => '<i class="fa fa-angle-right"></i>',
  30. 'prev_text' => '<i class="fa fa-angle-left"></i>',
  31. 'type' => 'array',
  32. 'end_size' => 4,
  33. 'mid_size' => 4,
  34. );
  35. // Paginaton Base for Different Types of Pages
  36. if ( is_front_page() && ( NULL != filter_input(INPUT_GET, 'selected_category') || NULL != filter_input(INPUT_GET, 'selected_jobtype') || NULL != filter_input(INPUT_GET, 'selected_location') || filter_input(INPUT_GET, 'search_keywords') ) ) {
  37. // Paginaton Base for Home Page & Static Front Page
  38. $big = 999999999; // Need an unlikely integer
  39. if ($wp_rewrite->using_permalinks()) {
  40. $url = explode('?', get_pagenum_link($big)); // Get URL without Query String
  41. $pagination_args['base'] = str_replace($big, '%#%', esc_url($url[0]));
  42. }
  43. } else {
  44. //Paginaton Base for WP Post/Page
  45. $pagination_args['base'] = @add_query_arg('page', '%#%');
  46. }
  47. /**
  48. * Modify query string.
  49. *
  50. * Remove query "page" argument from permalink
  51. */
  52. if (! ( NULL != filter_input(INPUT_GET, 'selected_category') || NULL != filter_input(INPUT_GET, 'selected_jobtype') || NULL != filter_input(INPUT_GET, 'selected_location') || filter_input(INPUT_GET, 'search_keywords') ) ) {
  53. if ($wp_rewrite->using_permalinks()) {
  54. $pagination_args['base'] = user_trailingslashit(trailingslashit(remove_query_arg('page', get_pagenum_link(1))) . '?page=%#%/', 'paged');
  55. }
  56. if (!empty($job_query->query_vars['s'])) {
  57. $pagination_args['add_args'] = array('s' => get_query_var('s'));
  58. }
  59. }
  60. $pagination = apply_filters('sjb_pagination_links_default_args', $pagination_args);
  61. // Retrieve paginated link for job posts
  62. $pages = paginate_links( $pagination );
  63. if ( is_array( $pages ) ) {
  64. $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
  65. ?>
  66. <nav aria-label="Page navigation">
  67. <ul class="pagination">
  68. <?php
  69. foreach ( $pages as $page ) {
  70. echo "<li class='list-item'>$page</li>";
  71. }
  72. ?>
  73. </ul>
  74. <div class="clearfix"></div>
  75. </nav>
  76. <?php
  77. }
  78. $html_pagination = ob_get_clean();
  79. /**
  80. * Modify the Job Meta - Company Tagline Template.
  81. *
  82. * @since 2.3.0
  83. *
  84. * @param html $html_company_tagline Company Tagline HTML.
  85. */
  86. echo apply_filters( 'sjb_pagination_template', $html_pagination );