WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/03/2014 09:39:37 PM (6 years ago)
Author:
iandstewart
Message:

Twenty Fifteen: Use new core navigation tags.

Props obenland, iamtakashi, fixes #30189

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfifteen/inc/template-tags.php

    r30072 r30216  
    99 * @since Twenty Fifteen 1.0
    1010 */
    11 
    12 if ( ! function_exists( 'twentyfifteen_paging_nav' ) ) :
    13 /**
    14  * Display navigation to next/previous set of posts when applicable.
    15  *
    16  * @since Twenty Fifteen 1.0
    17  * @uses paginate_links()
    18  *
    19  * @global WP_Query $wp_query WordPress Query object.
    20  */
    21 function twentyfifteen_paging_nav() {
    22     // Don't print empty markup if there's only one page.
    23     if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
    24         return;
    25     }
    26 
    27     // Set up paginated links.
    28     $links = paginate_links( array(
    29         'prev_text'          => esc_html__( 'Previous', 'twentyfifteen' ),
    30         'next_text'          => esc_html__( 'Next', 'twentyfifteen' ),
    31         'before_page_number' => '<span class="meta-nav">' . esc_html__( 'Page', 'twentyfifteen' ) . '</span>',
    32     ) );
    33 
    34     if ( $links ) :
    35     ?>
    36     <nav class="navigation pagination" role="navigation">
    37         <h2 class="screen-reader-text"><?php esc_html_e( 'Posts navigation', 'twentyfifteen' ); ?></h2>
    38         <div class="nav-links">
    39             <?php echo $links; ?>
    40         </div><!-- .nav-links -->
    41     </nav><!-- .pagination -->
    42     <?php
    43     endif;
    44 }
    45 endif;
    46 
    47 if ( ! function_exists( 'twentyfifteen_post_nav' ) ) :
    48 /**
    49  * Display navigation to next/previous post when applicable.
    50  *
    51  * @since Twenty Fifteen 1.0
    52  */
    53 function twentyfifteen_post_nav() {
    54     // Don't print empty markup if there's nowhere to navigate.
    55     $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
    56     $next     = get_adjacent_post( false, '', false );
    57 
    58     if ( ( ! $next && ! $previous ) || ( is_attachment() && 'attachment' == $previous->post_type ) ) {
    59         return;
    60     }
    61 
    62     $prev_class = $next_class = '';
    63 
    64     if ( $previous && has_post_thumbnail( $previous->ID ) ) {
    65         $prev_class = ' has-post-thumbnail';
    66     }
    67 
    68     if ( $next && has_post_thumbnail( $next->ID ) ) {
    69         $next_class = ' has-post-thumbnail';
    70     }
    71 
    72     ?>
    73     <nav class="navigation post-navigation" role="navigation">
    74         <h2 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'twentyfifteen' ); ?></h2>
    75         <div class="nav-links">
    76             <?php
    77             if ( is_attachment() ) :
    78                 previous_post_link( '<div class="nav-previous' . $prev_class . '">%link</div>', _x( '<span class="meta-nav">Published In</span><span class="post-title">%title</span>', 'Parent post link', 'twentyfifteen' ) );
    79             else :
    80                 previous_post_link( '<div class="nav-previous' . $prev_class . '">%link</div>', _x( '<span class="meta-nav">Previous</span><span class="post-title">%title</span>', 'Previous post link', 'twentyfifteen' ) );
    81                 next_post_link( '<div class="nav-next' . $next_class . '">%link</div>', _x( '<span class="meta-nav">Next</span><span class="post-title">%title</span>', 'Next post link', 'twentyfifteen' ) );
    82             endif;
    83             ?>
    84         </div><!-- .nav-links -->
    85     </nav><!-- .post-navigation -->
    86     <?php
    87 }
    88 endif;
    8911
    9012if ( ! function_exists( 'twentyfifteen_comment_nav' ) ) :
Note: See TracChangeset for help on using the changeset viewer.