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