Making WordPress.org


Ignore:
Timestamp:
02/15/2016 10:38:48 PM (11 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Handle migration of menu-ordered handbook page navigation functionality to handbook plugin.

  • Remove wporg_developer_post_nav_via_menu().
  • Use WPorg_Handbook_Navigation::navigate_via_menu() instead.
  • Adjust related styling references.

See #425.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r2437 r2508  
    6565                                        <?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'wporg' ) ); ?>
    6666                                        <?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'wporg' ) ); ?>
    67 
    68                                 </div>
    69                                 <!-- .nav-links -->
    70                         </nav><!-- .navigation -->
    71                 <?php
    72                 }
    73         endif;
    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">&larr;</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">&rarr;</span></a>',
    140                                                 esc_url( $next->url ),
    141                                                 esc_html( $next->title )
    142                                         );
    143                                 }
    144                                 ?>
    14567
    14668                                </div>
Note: See TracChangeset for help on using the changeset viewer.