[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom template tags for Twenty Fourteen 4 * 5 * @package WordPress 6 * @subpackage Twenty_Fourteen 7 * @since Twenty Fourteen 1.0 8 */ 9 10 if ( ! function_exists( 'twentyfourteen_paging_nav' ) ) : 11 /** 12 * Display navigation to next/previous set of posts when applicable. 13 * 14 * @since Twenty Fourteen 1.0 15 * 16 * @global WP_Query $wp_query WordPress Query object. 17 * @global WP_Rewrite $wp_rewrite WordPress Rewrite object. 18 */ 19 function twentyfourteen_paging_nav() { 20 global $wp_query, $wp_rewrite; 21 22 // Don't print empty markup if there's only one page. 23 if ( $wp_query->max_num_pages < 2 ) { 24 return; 25 } 26 27 $paged = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; 28 $pagenum_link = html_entity_decode( get_pagenum_link() ); 29 $query_args = array(); 30 $url_parts = explode( '?', $pagenum_link ); 31 32 if ( isset( $url_parts[1] ) ) { 33 wp_parse_str( $url_parts[1], $query_args ); 34 } 35 36 $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link ); 37 $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; 38 39 $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; 40 $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; 41 42 // Set up paginated links. 43 $links = paginate_links( 44 array( 45 'base' => $pagenum_link, 46 'format' => $format, 47 'total' => $wp_query->max_num_pages, 48 'current' => $paged, 49 'mid_size' => 1, 50 'add_args' => array_map( 'urlencode', $query_args ), 51 'prev_text' => __( '← Previous', 'twentyfourteen' ), 52 'next_text' => __( 'Next →', 'twentyfourteen' ), 53 ) 54 ); 55 56 if ( $links ) : 57 58 ?> 59 <nav class="navigation paging-navigation"> 60 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentyfourteen' ); ?></h1> 61 <div class="pagination loop-pagination"> 62 <?php echo $links; ?> 63 </div><!-- .pagination --> 64 </nav><!-- .navigation --> 65 <?php 66 endif; 67 } 68 endif; 69 70 if ( ! function_exists( 'twentyfourteen_post_nav' ) ) : 71 /** 72 * Display navigation to next/previous post when applicable. 73 * 74 * @since Twenty Fourteen 1.0 75 */ 76 function twentyfourteen_post_nav() { 77 // Don't print empty markup if there's nowhere to navigate. 78 $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); 79 $next = get_adjacent_post( false, '', false ); 80 81 if ( ! $next && ! $previous ) { 82 return; 83 } 84 85 ?> 86 <nav class="navigation post-navigation"> 87 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1> 88 <div class="nav-links"> 89 <?php 90 if ( is_attachment() ) : 91 previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) ); 92 else : 93 previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) ); 94 next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) ); 95 endif; 96 ?> 97 </div><!-- .nav-links --> 98 </nav><!-- .navigation --> 99 <?php 100 } 101 endif; 102 103 if ( ! function_exists( 'twentyfourteen_posted_on' ) ) : 104 /** 105 * Print HTML with meta information for the current post-date/time and author. 106 * 107 * @since Twenty Fourteen 1.0 108 */ 109 function twentyfourteen_posted_on() { 110 if ( is_sticky() && is_home() && ! is_paged() ) { 111 echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>'; 112 } 113 114 // Set up and print post meta information. 115 printf( 116 '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>', 117 esc_url( get_permalink() ), 118 esc_attr( get_the_date( 'c' ) ), 119 esc_html( get_the_date() ), 120 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), 121 get_the_author() 122 ); 123 } 124 endif; 125 126 /** 127 * Find out if blog has more than one category. 128 * 129 * @since Twenty Fourteen 1.0 130 * 131 * @return bool true if blog has more than 1 category 132 */ 133 function twentyfourteen_categorized_blog() { 134 $all_the_cool_cats = get_transient( 'twentyfourteen_category_count' ); 135 if ( false === $all_the_cool_cats ) { 136 // Create an array of all the categories that are attached to posts. 137 $all_the_cool_cats = get_categories( 138 array( 139 'hide_empty' => 1, 140 ) 141 ); 142 143 // Count the number of categories that are attached to the posts. 144 $all_the_cool_cats = count( $all_the_cool_cats ); 145 146 set_transient( 'twentyfourteen_category_count', $all_the_cool_cats ); 147 } 148 149 if ( $all_the_cool_cats > 1 || is_preview() ) { 150 // This blog has more than 1 category so twentyfourteen_categorized_blog() should return true. 151 return true; 152 } else { 153 // This blog has only 1 category so twentyfourteen_categorized_blog() should return false. 154 return false; 155 } 156 } 157 158 /** 159 * Flush out the transients used in twentyfourteen_categorized_blog. 160 * 161 * @since Twenty Fourteen 1.0 162 */ 163 function twentyfourteen_category_transient_flusher() { 164 // Like, beat it. Dig? 165 delete_transient( 'twentyfourteen_category_count' ); 166 } 167 add_action( 'edit_category', 'twentyfourteen_category_transient_flusher' ); 168 add_action( 'save_post', 'twentyfourteen_category_transient_flusher' ); 169 170 if ( ! function_exists( 'twentyfourteen_post_thumbnail' ) ) : 171 /** 172 * Display an optional post thumbnail. 173 * 174 * Wraps the post thumbnail in an anchor element on index 175 * views, or a div element when on single views. 176 * 177 * @since Twenty Fourteen 1.0 178 * @since Twenty Fourteen 1.4 Was made 'pluggable', or overridable. 179 */ 180 function twentyfourteen_post_thumbnail() { 181 if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { 182 return; 183 } 184 185 if ( is_singular() ) : 186 ?> 187 188 <div class="post-thumbnail"> 189 <?php 190 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) { 191 the_post_thumbnail( 'twentyfourteen-full-width' ); 192 } else { 193 the_post_thumbnail(); 194 } 195 ?> 196 </div> 197 198 <?php else : ?> 199 200 <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"> 201 <?php 202 if ( ( ! is_active_sidebar( 'sidebar-2' ) || is_page_template( 'page-templates/full-width.php' ) ) ) { 203 the_post_thumbnail( 'twentyfourteen-full-width' ); 204 } else { 205 the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) ); 206 } 207 ?> 208 </a> 209 210 <?php 211 endif; // End is_singular(). 212 } 213 endif; 214 215 if ( ! function_exists( 'twentyfourteen_excerpt_more' ) && ! is_admin() ) : 216 /** 217 * Replaces "[...]" (appended to automatically generated excerpts) with ... 218 * and a Continue reading link. 219 * 220 * @since Twenty Fourteen 1.3 221 * 222 * @param string $more Default Read More excerpt link. 223 * @return string Filtered Read More excerpt link. 224 */ 225 function twentyfourteen_excerpt_more( $more ) { 226 $link = sprintf( 227 '<a href="%1$s" class="more-link">%2$s</a>', 228 esc_url( get_permalink( get_the_ID() ) ), 229 /* translators: %s: Post title. Only visible to screen readers. */ 230 sprintf( __( 'Continue reading %s <span class="meta-nav">→</span>', 'twentyfourteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' ) 231 ); 232 return ' … ' . $link; 233 } 234 add_filter( 'excerpt_more', 'twentyfourteen_excerpt_more' ); 235 endif; 236 237 if ( ! function_exists( 'wp_body_open' ) ) : 238 /** 239 * Fire the wp_body_open action. 240 * 241 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 242 * 243 * @since Twenty Fourteen 2.7 244 */ 245 function wp_body_open() { 246 /** 247 * Triggered after the opening <body> tag. 248 * 249 * @since Twenty Fourteen 2.7 250 */ 251 do_action( 'wp_body_open' ); 252 } 253 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Oct 4 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |