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