| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom Twenty Sixteen template tags 4 * 5 * Eventually, some of the functionality here could be replaced by core features. 6 * 7 * @package WordPress 8 * @subpackage Twenty_Sixteen 9 * @since Twenty Sixteen 1.0 10 */ 11 12 if ( ! function_exists( 'twentysixteen_entry_meta' ) ) : 13 /** 14 * Prints HTML with meta information for the categories, tags. 15 * 16 * Create your own twentysixteen_entry_meta() function to override in a child theme. 17 * 18 * @since Twenty Sixteen 1.0 19 */ 20 function twentysixteen_entry_meta() { 21 if ( 'post' === get_post_type() ) { 22 /** 23 * Filters the Twenty Sixteen entry meta avatar size. 24 * 25 * @since Twenty Sixteen 1.0 26 * 27 * @param int $size The avatar height and width size in pixels. 28 */ 29 $author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 ); 30 printf( 31 '<span class="byline">%1$s<span class="screen-reader-text">%2$s </span><span class="author vcard"><a class="url fn n" href="%3$s">%4$s</a></span></span>', 32 get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ), 33 /* translators: Hidden accessibility text. */ 34 _x( 'Author', 'Used before post author name.', 'twentysixteen' ), 35 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), 36 get_the_author() 37 ); 38 } 39 40 if ( in_array( get_post_type(), array( 'post', 'attachment' ), true ) ) { 41 twentysixteen_entry_date(); 42 } 43 44 $format = get_post_format(); 45 if ( current_theme_supports( 'post-formats', $format ) ) { 46 printf( 47 '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>', 48 sprintf( 49 '<span class="screen-reader-text">%s </span>', 50 /* translators: Hidden accessibility text. */ 51 _x( 'Format', 'Used before post format.', 'twentysixteen' ) 52 ), 53 esc_url( get_post_format_link( $format ) ), 54 get_post_format_string( $format ) 55 ); 56 } 57 58 if ( 'post' === get_post_type() ) { 59 twentysixteen_entry_taxonomies(); 60 } 61 62 if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { 63 echo '<span class="comments-link">'; 64 /* translators: %s: Post title. Only visible to screen readers. */ 65 comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentysixteen' ), get_the_title() ) ); 66 echo '</span>'; 67 } 68 } 69 endif; 70 71 if ( ! function_exists( 'twentysixteen_entry_date' ) ) : 72 /** 73 * Prints HTML with date information for current post. 74 * 75 * Create your own twentysixteen_entry_date() function to override in a child theme. 76 * 77 * @since Twenty Sixteen 1.0 78 */ 79 function twentysixteen_entry_date() { 80 $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; 81 82 if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { 83 $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; 84 } 85 86 $time_string = sprintf( 87 $time_string, 88 esc_attr( get_the_date( 'c' ) ), 89 get_the_date(), 90 esc_attr( get_the_modified_date( 'c' ) ), 91 get_the_modified_date() 92 ); 93 94 printf( 95 '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>', 96 /* translators: Hidden accessibility text. */ 97 _x( 'Posted on', 'Used before publish date.', 'twentysixteen' ), 98 esc_url( get_permalink() ), 99 $time_string 100 ); 101 } 102 endif; 103 104 if ( ! function_exists( 'twentysixteen_entry_taxonomies' ) ) : 105 /** 106 * Prints HTML with category and tags for current post. 107 * 108 * Create your own twentysixteen_entry_taxonomies() function to override in a child theme. 109 * 110 * @since Twenty Sixteen 1.0 111 */ 112 function twentysixteen_entry_taxonomies() { 113 $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) ); 114 if ( $categories_list && twentysixteen_categorized_blog() ) { 115 printf( 116 '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', 117 /* translators: Hidden accessibility text. */ 118 _x( 'Categories', 'Used before category names.', 'twentysixteen' ), 119 $categories_list 120 ); 121 } 122 123 $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) ); 124 if ( $tags_list && ! is_wp_error( $tags_list ) ) { 125 printf( 126 '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', 127 /* translators: Hidden accessibility text. */ 128 _x( 'Tags', 'Used before tag names.', 'twentysixteen' ), 129 $tags_list 130 ); 131 } 132 } 133 endif; 134 135 if ( ! function_exists( 'twentysixteen_post_thumbnail' ) ) : 136 /** 137 * Displays an optional post thumbnail. 138 * 139 * Wraps the post thumbnail in an anchor element on index views, or a div 140 * element when on single views. 141 * 142 * Create your own twentysixteen_post_thumbnail() function to override in a child theme. 143 * 144 * @since Twenty Sixteen 1.0 145 */ 146 function twentysixteen_post_thumbnail() { 147 if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { 148 return; 149 } 150 151 if ( is_singular() ) : 152 ?> 153 154 <div class="post-thumbnail"> 155 <?php the_post_thumbnail(); ?> 156 </div><!-- .post-thumbnail --> 157 158 <?php else : ?> 159 160 <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"> 161 <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); ?> 162 </a> 163 164 <?php 165 endif; // End is_singular(). 166 } 167 endif; 168 169 if ( ! function_exists( 'twentysixteen_excerpt' ) ) : 170 /** 171 * Displays the optional excerpt. 172 * 173 * Wraps the excerpt in a div element. 174 * 175 * Create your own twentysixteen_excerpt() function to override in a child theme. 176 * 177 * @since Twenty Sixteen 1.0 178 * 179 * @param string $css_class Optional. Class string of the div element. Defaults to 'entry-summary'. 180 */ 181 function twentysixteen_excerpt( $css_class = 'entry-summary' ) { 182 $css_class = esc_attr( $css_class ); 183 184 if ( has_excerpt() || is_search() ) : 185 ?> 186 <div class="<?php echo $css_class; ?>"> 187 <?php the_excerpt(); ?> 188 </div><!-- .<?php echo $css_class; ?> --> 189 <?php 190 endif; 191 } 192 endif; 193 194 if ( ! function_exists( 'twentysixteen_excerpt_more' ) && ! is_admin() ) : 195 /** 196 * Replaces "[...]" (appended to automatically generated excerpts) with ... and 197 * a 'Continue reading' link. 198 * 199 * Create your own twentysixteen_excerpt_more() function to override in a child theme. 200 * 201 * @since Twenty Sixteen 1.0 202 * 203 * @return string 'Continue reading' link prepended with an ellipsis. 204 */ 205 function twentysixteen_excerpt_more() { 206 $link = sprintf( 207 '<a href="%1$s" class="more-link">%2$s</a>', 208 esc_url( get_permalink( get_the_ID() ) ), 209 /* translators: %s: Post title. Only visible to screen readers. */ 210 sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), get_the_title( get_the_ID() ) ) 211 ); 212 return ' … ' . $link; 213 } 214 add_filter( 'excerpt_more', 'twentysixteen_excerpt_more' ); 215 endif; 216 217 if ( ! function_exists( 'twentysixteen_categorized_blog' ) ) : 218 /** 219 * Determines whether blog/site has more than one category. 220 * 221 * Create your own twentysixteen_categorized_blog() function to override in a child theme. 222 * 223 * @since Twenty Sixteen 1.0 224 * 225 * @return bool True if there is more than one category, false otherwise. 226 */ 227 function twentysixteen_categorized_blog() { 228 $all_the_cool_cats = get_transient( 'twentysixteen_categories' ); 229 if ( false === $all_the_cool_cats ) { 230 // Create an array of all the categories that are attached to posts. 231 $all_the_cool_cats = get_categories( 232 array( 233 'fields' => 'ids', 234 // We only need to know if there is more than one category. 235 'number' => 2, 236 ) 237 ); 238 239 // Count the number of categories that are attached to the posts. 240 $all_the_cool_cats = count( $all_the_cool_cats ); 241 242 set_transient( 'twentysixteen_categories', $all_the_cool_cats ); 243 } 244 245 if ( $all_the_cool_cats > 1 || is_preview() ) { 246 // This blog has more than 1 category so twentysixteen_categorized_blog() should return true. 247 return true; 248 } else { 249 // This blog has only 1 category so twentysixteen_categorized_blog() should return false. 250 return false; 251 } 252 } 253 endif; 254 255 /** 256 * Flushes out the transients used in twentysixteen_categorized_blog(). 257 * 258 * @since Twenty Sixteen 1.0 259 */ 260 function twentysixteen_category_transient_flusher() { 261 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 262 return; 263 } 264 // Like, beat it. Dig? 265 delete_transient( 'twentysixteen_categories' ); 266 } 267 add_action( 'edit_category', 'twentysixteen_category_transient_flusher' ); 268 add_action( 'save_post', 'twentysixteen_category_transient_flusher' ); 269 270 if ( ! function_exists( 'twentysixteen_the_custom_logo' ) ) : 271 /** 272 * Displays the optional custom logo. 273 * 274 * Does nothing if the custom logo is not available. 275 * 276 * @since Twenty Sixteen 1.2 277 */ 278 function twentysixteen_the_custom_logo() { 279 if ( function_exists( 'the_custom_logo' ) ) { 280 the_custom_logo(); 281 } 282 } 283 endif; 284 285 if ( ! function_exists( 'wp_body_open' ) ) : 286 /** 287 * Fires the wp_body_open action. 288 * 289 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 290 * 291 * @since Twenty Sixteen 2.0 292 */ 293 function wp_body_open() { 294 /** 295 * Triggered after the opening <body> tag. 296 * 297 * @since Twenty Sixteen 2.0 298 */ 299 do_action( 'wp_body_open' ); 300 } 301 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Jul 22 08:20:19 2026 | Cross-referenced by PHPXref |