Advertisement
Guest User

pagination issue

a guest
Nov 12th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. add_action( 'genesis_after_entry', 'genesis_after_entry_widget_area' );
  2. /**
  3. * Display after-entry widget area on the genesis_after_entry action hook.
  4. *
  5. * @since 2.1.0
  6. *
  7. * @uses genesis_widget_area() Output widget area.
  8. */
  9. function genesis_after_entry_widget_area() {
  10.  
  11. if ( ! is_singular( 'post' ) || ! current_theme_supports( 'genesis-after-entry-widget-area' ) ) {
  12. return;
  13. }
  14.  
  15. genesis_widget_area( 'after-entry', array(
  16. 'before' => '<div class="after-entry widget-area">',
  17. 'after' => '</div>',
  18. ) );
  19.  
  20. }
  21.  
  22. add_action( 'genesis_after_endwhile', 'genesis_posts_nav' );
  23. /**
  24. * Conditionally echo archive pagination in a format dependent on chosen setting.
  25. *
  26. * This is shown at the end of archives to get to another page of entries.
  27. *
  28. * @since 0.2.3
  29. *
  30. * @uses genesis_get_option() Get theme setting value.
  31. * @uses genesis_prev_next_posts_nav() Prev and Next links.
  32. * @uses genesis_numeric_posts_nav() Numbered links.
  33. */
  34. function genesis_posts_nav() {
  35.  
  36. if ( 'numeric' === genesis_get_option( 'posts_nav' ) )
  37. genesis_numeric_posts_nav();
  38. else
  39. genesis_prev_next_posts_nav();
  40.  
  41. }
  42.  
  43. /**
  44. * Echo archive pagination in Previous Posts / Next Posts format.
  45. *
  46. * Applies `genesis_prev_link_text` and `genesis_next_link_text` filters.
  47. *
  48. * @since 0.2.2
  49. */
  50. function genesis_prev_next_posts_nav() {
  51.  
  52. $prev_link = get_previous_posts_link( apply_filters( 'genesis_prev_link_text', '&#x000AB;' . __( 'Previous Page', 'genesis' ) ) );
  53. $next_link = get_next_posts_link( apply_filters( 'genesis_next_link_text', __( 'Next Page', 'genesis' ) . '&#x000BB;' ) );
  54.  
  55. $prev = $prev_link ? '<div class="pagination-previous alignleft">' . $prev_link . '</div>' : '';
  56. $next = $next_link ? '<div class="pagination-next alignright">' . $next_link . '</div>' : '';
  57.  
  58. $nav = genesis_markup( array(
  59. 'html5' => '<div %s>',
  60. 'xhtml' => '<div class="navigation">',
  61. 'context' => 'archive-pagination',
  62. 'echo' => false,
  63. ) );
  64.  
  65. $nav .= $prev;
  66. $nav .= $next;
  67. $nav .= '</div>';
  68.  
  69. if ( $prev || $next )
  70. echo $nav;
  71. }
  72.  
  73. /**
  74. * Echo archive pagination in page numbers format.
  75. *
  76. * Applies the `genesis_prev_link_text` and `genesis_next_link_text` filters.
  77. *
  78. * The links, if needed, are ordered as:
  79. *
  80. * * previous page arrow,
  81. * * first page,
  82. * * up to two pages before current page,
  83. * * current page,
  84. * * up to two pages after the current page,
  85. * * last page,
  86. * * next page arrow.
  87. *
  88. * @since 0.2.3
  89. *
  90. * @global WP_Query $wp_query Query object.
  91. *
  92. * @return null Return early if on a single post or page, or only one page present.
  93. */
  94. function genesis_numeric_posts_nav() {
  95.  
  96. if( is_singular() )
  97. return;
  98.  
  99. global $wp_query;
  100.  
  101. //* Stop execution if there's only 1 page
  102. if( $wp_query->max_num_pages <= 1 )
  103. return;
  104.  
  105. $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
  106. $max = intval( $wp_query->max_num_pages );
  107.  
  108. //* Add current page to the array
  109. if ( $paged >= 1 )
  110. $links[] = $paged;
  111.  
  112. //* Add the pages around the current page to the array
  113. if ( $paged >= 3 ) {
  114. $links[] = $paged - 1;
  115. $links[] = $paged - 2;
  116. }
  117.  
  118. if ( ( $paged + 2 ) <= $max ) {
  119. $links[] = $paged + 2;
  120. $links[] = $paged + 1;
  121. }
  122.  
  123. genesis_markup( array(
  124. 'html5' => '<div %s>',
  125. 'xhtml' => '<div class="navigation">',
  126. 'context' => 'archive-pagination',
  127. ) );
  128.  
  129. echo '<ul>';
  130.  
  131. //* Previous Post Link
  132. if ( get_previous_posts_link() )
  133. printf( '<li class="pagination-previous">%s</li>' . "\n", get_previous_posts_link( apply_filters( 'genesis_prev_link_text', '&#x000AB;' . __( 'Previous Page', 'genesis' ) ) ) );
  134.  
  135. //* Link to first page, plus ellipses if necessary
  136. if ( ! in_array( 1, $links ) ) {
  137.  
  138. $class = 1 == $paged ? ' class="active"' : '';
  139.  
  140. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
  141.  
  142. if ( ! in_array( 2, $links ) )
  143. echo '<li class="pagination-omission">&#x02026;</li>';
  144.  
  145. }
  146.  
  147. //* Link to current page, plus 2 pages in either direction if necessary
  148. sort( $links );
  149. foreach ( (array) $links as $link ) {
  150. $class = $paged == $link ? ' class="active"' : '';
  151. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
  152. }
  153.  
  154. //* Link to last page, plus ellipses if necessary
  155. if ( ! in_array( $max, $links ) ) {
  156.  
  157. if ( ! in_array( $max - 1, $links ) )
  158. echo '<li class="pagination-omission">&#x02026;</li>' . "\n";
  159.  
  160. $class = $paged == $max ? ' class="active"' : '';
  161. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
  162.  
  163. }
  164.  
  165. //* Next Post Link
  166. if ( get_next_posts_link() )
  167. printf( '<li class="pagination-next">%s</li>' . "\n", get_next_posts_link( apply_filters( 'genesis_next_link_text', __( 'Next Page', 'genesis' ) . '&#x000BB;' ) ) );
  168.  
  169. echo '</ul></div>' . "\n";
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement