- Timestamp:
- 08/15/2013 12:24:27 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyfourteen/inc/template-tags.php
r25021 r25023 2 2 /** 3 3 * Custom template tags for this theme. 4 *5 * Eventually, some of the functionality here could be replaced by core features6 4 * 7 5 * @package WordPress … … 9 7 */ 10 8 11 if ( ! function_exists( 'twentyfourteen_content_nav' ) ) : 12 /** 13 * Display navigation to next/previous pages when applicable 14 * 15 */ 16 function twentyfourteen_content_nav( $nav_id ) { 17 global $wp_query, $post; 18 19 // Don't print empty markup on single pages if there's nowhere to navigate. 20 if ( is_single() ) { 21 $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true ); 22 $next = get_adjacent_post( false, '', false ); 23 24 if ( ! $next && ! $previous ) 25 return; 26 } 27 28 // Don't print empty markup in archives if there's only one page. 29 if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) ) 9 if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) : 10 /** 11 * Displays navigation to next/previous set of posts when applicable. 12 * 13 * @return void 14 */ 15 function twentyfourteen_paging_nav() { 16 // Don't print empty markup if there's only one page. 17 if ( $GLOBALS['wp_query']->max_num_pages < 2 ) 30 18 return; 31 19 32 $nav_class = 'site-navigation paging-navigation'; 33 if ( is_single() ) 34 $nav_class = 'site-navigation post-navigation'; 35 36 ?> 37 <nav role="navigation" id="<?php echo $nav_id; ?>" class="<?php echo $nav_class; ?>"> 20 $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; 21 $pagenum_link = html_entity_decode( get_pagenum_link() ); 22 $query_args = array(); 23 $url_parts = explode( '?', $pagenum_link ); 24 25 if ( isset( $url_parts[1] ) ) 26 wp_parse_str( $url_parts[1], $query_args ); 27 28 $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); 29 $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; 30 31 $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; 32 $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%'; 33 34 $links = paginate_links( array( 35 'base' => $pagenum_link, 36 'format' => $format, 37 'total' => $GLOBALS['wp_query']->max_num_pages, 38 'current' => $paged, 39 'mid_size' => 1, 40 'add_args' => array_map( 'urlencode', $query_args ), 41 'prev_text' => __( '← Previous', 'twentyfourteen' ), 42 'next_text' => __( 'Next →', 'twentyfourteen' ), 43 ) ); 44 45 if ( $links ) : 46 47 ?> 48 <nav class="navigation paging-navigation" role="navigation"> 49 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1> 50 <div class="pagination loop-pagination"> 51 <?php echo $links; ?> 52 </div><!-- .pagination --> 53 </nav><!-- .navigation --> 54 <?php 55 endif; 56 } 57 endif; 58 59 if ( ! function_exists( 'twentyfourteen_post_nav' ) ) : 60 /** 61 * Displays navigation to next/previous post when applicable. 62 * 63 * @return void 64 */ 65 function twentyfourteen_post_nav() { 66 // Don't print empty markup if there's nowhere to navigate. 67 $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); 68 $next = get_adjacent_post( false, '', false ); 69 70 if ( ! $next && ! $previous ) 71 return; 72 73 ?> 74 <nav class="navigation post-navigation" role="navigation"> 38 75 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1> 39 40 <?php if ( is_single() ) : // navigation links for single posts ?> 41 42 <?php previous_post_link( '%link', __( '<div class="nav-previous"><span class="meta-nav">Previous Post</span>%title</div>', 'twentyfourteen' ) ); ?> 43 <?php next_post_link( '%link', __( '<div class="nav-next"><span class="meta-nav">Next Post</span>%title</div>', 'twentyfourteen' ) ); ?> 44 45 <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?> 46 47 <div class="pagination loop-pagination"> 48 <?php 49 /* Get the current page. */ 50 $current = ( get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1 ); 51 52 /* Get the max number of pages. */ 53 $max_num_pages = intval( $wp_query->max_num_pages ); 54 55 /* Set up arguments for the paginate_links() function. */ 56 $args = array( 57 'base' => add_query_arg( 'paged', '%#%' ), 58 'format' => '', 59 'total' => $max_num_pages, 60 'current' => $current, 61 'prev_text' => __( '← Previous', 'twentyfourteen' ), 62 'next_text' => __( 'Next →', 'twentyfourteen' ), 63 'mid_size' => 1 64 ); 65 66 echo paginate_links( $args ) 67 ?> 68 </div> 69 <?php endif; ?> 70 71 </nav><!-- #<?php echo $nav_id; ?> --> 72 <?php 73 } 74 endif; // twentyfourteen_content_nav 76 <div class="nav-links"> 77 <?php 78 previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) ); 79 next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) ); 80 ?> 81 </div><!-- .nav-links --> 82 </nav><!-- .navigation --> 83 <?php 84 } 85 endif; 75 86 76 87 if ( ! function_exists( 'twentyfourteen_comment' ) ) : … … 131 142 * Prints HTML with meta information for the current post-date/time and author. 132 143 * 144 * @return void 133 145 */ 134 146 function twentyfourteen_posted_on() { … … 151 163 * Returns true if a blog has more than 1 category 152 164 * 165 * @return boolean 153 166 */ 154 167 function twentyfourteen_categorized_blog() {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)