Make WordPress Core

Changeset 30457


Ignore:
Timestamp:
11/20/2014 03:18:53 PM (10 years ago)
Author:
johnbillion
Message:

Improvements to the output of the new post navigation template functions, including swapping the position of the previous and next links.

See #29808
Props obenland

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r30263 r30457  
    21932193 *     Optional. Default post navigation arguments.
    21942194 *
    2195  *     @type string $prev_text Anchor text to display in the previous post link.
    2196  *                             Default: `<span class="meta-nav">&larr;</span> %title`.
    2197  *     @type string $next_text Anchor text to display in the next post link.
    2198  *                             Default: `%title <span class="meta-nav">&rarr;</span>`.
     2195 *     @type string $prev_text          Anchor text to display in the previous post link. Default: `%title`.
     2196 *     @type string $next_text          Anchor text to display in the next post link. Default: `%title`.
     2197 *     @type string $screen_reader_text Screen reader text for nav element. Default: 'Post navigation'.
    21992198 * }
    22002199 * @return string Markup for post links.
     
    22022201function get_the_post_navigation( $args = array() ) {
    22032202    $args = wp_parse_args( $args, array(
    2204         'prev_text' => _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link' ),
    2205         'next_text' => _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link' ),
     2203        'prev_text'          => '%title',
     2204        'next_text'          => '%title',
     2205        'screen_reader_text' => __( 'Post navigation' ),
    22062206    ) );
    22072207
     
    22112211
    22122212    // Only add markup if there's somewhere to navigate to.
    2213     if ( $next || $previous ) {
    2214         $navigation = _navigation_markup( $next . $previous, 'post-navigation', __( 'Post navigation' ) );
     2213    if ( $previous || $next ) {
     2214        $navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'] );
    22152215    }
    22162216
     
    22392239 *     Optional. Default paging navigation arguments.
    22402240 *
    2241  *     @type string $prev_text Anchor text to display in the previous posts link.
    2242  *                             Default: `<span class="meta-nav">&larr;</span> Older posts`.
    2243  *     @type string $next_text Anchor text to display in the next posts link.
    2244  *                             Default: `Newer posts <span class="meta-nav">&rarr;</span>`.
     2241 *     @type string $prev_text          Anchor text to display in the previous posts link. Default: `Older posts`.
     2242 *     @type string $next_text          Anchor text to display in the next posts link. Default: `Newer posts`.
     2243 *     @type string $screen_reader_text Screen reader text for nav element. Default: 'Posts navigation'.
    22452244 * }
    22462245 * @return string Markup for paging links.
     
    22522251    if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
    22532252        $args = wp_parse_args( $args, array(
    2254             'prev_text' => __( '<span class="meta-nav">&larr;</span> Older posts' ),
    2255             'next_text' => __( 'Newer posts <span class="meta-nav">&rarr;</span>' ),
     2253            'prev_text'          => __( 'Older posts' ),
     2254            'next_text'          => __( 'Newer posts' ),
     2255            'screen_reader_text' => __( 'Posts navigation' ),
    22562256        ) );
    22572257
    2258         $next_link = get_next_posts_link( $args['prev_text'] );
    2259         $prev_link = get_previous_posts_link( $args['next_text'] );
     2258        $next_link = get_previous_posts_link( $args['next_text'] );
     2259        $prev_link = get_next_posts_link( $args['prev_text'] );
     2260
     2261        if ( $prev_link ) {
     2262            $navigation .= '<div class="nav-previous">' . $prev_link . '</div>';
     2263        }
    22602264
    22612265        if ( $next_link ) {
    2262             $navigation .= '<div class="nav-previous">' . $next_link . '</div>';
     2266            $navigation .= '<div class="nav-next">' . $next_link . '</div>';
    22632267        }
    22642268
    2265         if ( $prev_link ) {
    2266             $navigation .= '<div class="nav-next">' . $prev_link . '</div>';
    2267         }
    2268 
    2269         $navigation = _navigation_markup( $navigation );
     2269        $navigation = _navigation_markup( $navigation, 'paging-navigation', $args['screen_reader_text'] );
    22702270    }
    22712271
     
    22912291 *
    22922292 * @param array $args {
    2293  *     Optional. Default pagination arguments.
    2294  *
    2295  *     @type string $base               URL to be used to create the paginated links.
    2296  *                                      Example: `http://example.com/all_posts.php%_%`
    2297  *                                      The `%_%` is required and will be replaced by the contents of the
    2298  *                                      'format' argument.
    2299  *                                      Default: Current page number link with appended `%_%`.
    2300  *     @type string $format             Used to replace the page number. Example: `?page=%#%`
    2301  *                                      The `%#%` is required and will be replaced with the page number.
    2302  *                                      Default: Current permalink format with appended `%#%`.
    2303  *     @type int    $total              The total amount of pages. Default: Value of 'max_num_pages' of current query.
    2304  *     @type int    $current            The current page number. Default: Value of 'paged' query var.
    2305  *     @type bool   $prev_next          Whether to include previous and next links. Default: true.
    2306  *     @type string $prev_text          Anchor text to display in the previous posts link. Default: `&larr; Previous`.
    2307  *     @type string $next_text          Anchor text to display in the next posts link. Default: `Next &rarr;`.
    2308  *     @type bool   $show_all           Whether to show all pages.
    2309  *                                      Default: false, shows short list of the pages near the current page.
    2310  *     @type int    $end_size           Amount of numbers on either the start and the end list edges. Default: 1.
    2311  *     @type int    $mid_size           Amount of numbers to either side of current page but not including current page.
    2312  *                                      Default: 1.
    2313  *     @type array  $add_args           Query vars to be added to the links. Accepts an associative array of arguments.
    2314  *                                      Default: Empty array.
    2315  *     @type string $before_page_number Text to prepend to the anchor text. Default: Empty string.
    2316  *     @type string $after_page_number  Text to append to the anchor text. Default: Empty string.
     2293 *     Optional. Default pagination arguments. {@see paginate_links()}
     2294 *
     2295 *     @type string $screen_reader_text Screen reader text for navigation element. Default: 'Posts navigation'.
    23172296 * }
    23182297 * @return string Markup for pagination links.
     
    23242303    if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
    23252304        $args = wp_parse_args( $args, array(
    2326             'mid_size'  => 1,
    2327             'prev_text' => __( '&larr; Previous' ),
    2328             'next_text' => __( 'Next &rarr;' ),
     2305            'mid_size'           => 1,
     2306            'prev_text'          => __( 'Previous' ),
     2307            'next_text'          => __( 'Next' ),
     2308            'screen_reader_text' => __( 'Posts navigation' ),
    23292309        ) );
    23302310        // Make sure we get plain links, so we can work with it.
     
    23342314        $links = paginate_links( $args );
    23352315
    2336         // `navigation_markup()` expects a string, `paginate_links()` can return an array.
    2337         if ( $links && ! is_array( $links ) ) {
    2338             $navigation = _navigation_markup( $links, 'pagination' );
     2316        if ( $links ) {
     2317            $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] );
    23392318        }
    23402319    }
     
    23732352    $template = '
    23742353    <nav class="navigation %1$s" role="navigation">
    2375         <h1 class="screen-reader-text">%2$s</h1>
     2354        <h2 class="screen-reader-text">%2$s</h2>
    23762355        <div class="nav-links">%3$s</div>
    23772356    </nav>';
Note: See TracChangeset for help on using the changeset viewer.