Changeset 922 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
- Timestamp:
- 10/21/2014 04:53:25 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
r875 r922 73 73 endif; 74 74 75 if ( ! function_exists( 'wporg_developer_post_nav_via_menu' ) ) : 76 /** 77 * Outputs previous and/or next post navigation links using the 78 * specified menu to inform navigation ordering. 79 * 80 * @param string $menu_name The name of the menu to use for nav ordering. 81 */ 82 function wporg_developer_post_nav_via_menu( $menu_name ) { 83 // Get the items for the specified menu 84 if ( ! $menu_items = wp_get_nav_menu_items( $menu_name ) ) { 85 return; 86 } 87 88 // Get ids for all menu objects 89 $menu_ids = wp_list_pluck( $menu_items, 'object_id' ); 90 91 // Get current post 92 if ( ! $post = get_post() ) { 93 return; 94 } 95 96 // Index of current post in menu. Return if not in menu. 97 $i = array_search( $post->ID, $menu_ids ); 98 if ( false === $i ) { 99 return; 100 } 101 102 // Find the previous post (note: preview menu item may not be a post) 103 $previous = null; 104 for ( $n = $i-1; $n >= 0; $n-- ) { 105 if ( isset( $menu_items[ $n ] ) && is_a( $menu_items[ $n ], 'WP_Post' ) ) { 106 $previous = $menu_items[ $n ]; 107 break; 108 } 109 } 110 111 // Find the next post (note: next menu item may not be a post) 112 $next = null; 113 $max = count( $menu_items ); 114 for ( $n = $i+1; $n < $max; $n++ ) { 115 if ( isset( $menu_items[ $n ] ) && is_a( $menu_items[ $n ], 'WP_Post' ) ) { 116 $next = $menu_items[ $n ]; 117 break; 118 } 119 } 120 121 if ( ! $previous && ! $next ) { 122 return; 123 } 124 ?> 125 126 <nav class="navigation post-navigation" role="navigation"> 127 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'wporg' ); ?></h1> 128 <div class="nav-links"> 129 130 <?php 131 if ( $previous ) { 132 printf( '<a href="%s" rel="previous"><span class="meta-nav">←</span> %s</a>', 133 esc_url( $previous->url ), 134 esc_html( $previous->title ) 135 ); 136 } 137 138 if ( $next ) { 139 printf( '<a href="%s" rel="next">%s <span class="meta-nav">→</span></a>', 140 esc_url( $next->url ), 141 esc_html( $next->title ) 142 ); 143 } 144 ?> 145 146 </div> 147 <!-- .nav-links --> 148 </nav><!-- .navigation --> 149 <?php 150 } 151 endif; 152 75 153 if ( ! function_exists( 'wporg_developer_user_note' ) ) : 76 154 /** … … 99 177 100 178 <footer class="comment-meta"> 179 <?php DevHub_User_Submitted_Content_Voting::show_voting(); ?> 101 180 <div class="comment-author vcard"> 102 181 <span class="comment-author-attribution"> … … 125 204 </time> 126 205 </a> 127 <?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link"> ', '</span>' ); ?>206 <?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link">— ', '</span>' ); ?> 128 207 </div> 129 208 <!-- .comment-metadata -->
Note: See TracChangeset
for help on using the changeset viewer.