Guest User

Untitled

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