Guest User

Untitled

a guest
Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. //Pagination
  2. function g2p_pagination() {
  3.  
  4. if( is_singular() )
  5. return;
  6.  
  7. global $wp_query;
  8.  
  9. /** Stop execution if there's only 1 page */
  10. if( $wp_query->max_num_pages <= 1 )
  11. return;
  12.  
  13. $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
  14. $max = intval( $wp_query->max_num_pages );
  15.  
  16. /** Add current page to the array */
  17. if ( $paged >= 1 )
  18. $links[] = $paged;
  19.  
  20. /** Add the pages around the current page to the array */
  21. if ( $paged >= 3 ) {
  22. $links[] = $paged - 1;
  23. $links[] = $paged - 2;
  24. }
  25.  
  26. if ( ( $paged + 2 ) <= $max ) {
  27. $links[] = $paged + 2;
  28. $links[] = $paged + 1;
  29. }
  30.  
  31. echo '<div class="navigation"><ul>' . "\n";
  32.  
  33. /** Previous Post Link */
  34. if ( get_previous_posts_link() )
  35. printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
  36.  
  37. /** Link to first page, plus ellipses if necessary */
  38. if ( ! in_array( 1, $links ) ) {
  39. $class = 1 == $paged ? ' class="active"' : '';
  40.  
  41. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
  42.  
  43. if ( ! in_array( 2, $links ) )
  44. echo '<li>…</li>';
  45. }
  46.  
  47. /** Link to current page, plus 2 pages in either direction if necessary */
  48. sort( $links );
  49. foreach ( (array) $links as $link ) {
  50. $class = $paged == $link ? ' class="active"' : '';
  51. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
  52. }
  53.  
  54. /** Link to last page, plus ellipses if necessary */
  55. if ( ! in_array( $max, $links ) ) {
  56. if ( ! in_array( $max - 1, $links ) )
  57. echo '<li>…</li>' . "\n";
  58.  
  59. $class = $paged == $max ? ' class="active"' : '';
  60. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
  61. }
  62.  
  63. /** Next Post Link */
  64. if ( get_next_posts_link() )
  65. printf( '<li>%s</li>' . "\n", get_next_posts_link() );
  66.  
  67. echo '</ul></div>' . "\n";
  68. }
  69. //End of pagination
Add Comment
Please, Sign In to add comment