3 * Custom Twenty Sixteen template tags
5 * Eventually, some of the functionality here could be replaced by core features.
8 * @subpackage Twenty_Sixteen
9 * @since Twenty Sixteen 1.0
12 if ( ! function_exists( 'twentysixteen_entry_meta' ) ) :
14 * Prints HTML with meta information for the categories, tags.
16 * Create your own twentysixteen_entry_meta() function to override in a child theme.
18 * @since Twenty Sixteen 1.0
20 function twentysixteen_entry_meta() {
21 if ( 'post' === get_post_type() ) {
22 $author_avatar_size = apply_filters( 'twentysixteen_author_avatar_size', 49 );
23 printf( '<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>',
24 get_avatar( get_the_author_meta( 'user_email' ), $author_avatar_size ),
25 _x( 'Author', 'Used before post author name.', 'twentysixteen' ),
26 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
31 if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
32 twentysixteen_entry_date();
35 $format = get_post_format();
36 if ( current_theme_supports( 'post-formats', $format ) ) {
37 printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
38 sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentysixteen' ) ),
39 esc_url( get_post_format_link( $format ) ),
40 get_post_format_string( $format )
44 if ( 'post' === get_post_type() ) {
45 twentysixteen_entry_taxonomies();
48 if ( ! is_singular() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
49 echo '<span class="comments-link">';
50 comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentysixteen' ), get_the_title() ) );
56 if ( ! function_exists( 'twentysixteen_entry_date' ) ) :
58 * Prints HTML with date information for current post.
60 * Create your own twentysixteen_entry_date() function to override in a child theme.
62 * @since Twenty Sixteen 1.0
64 function twentysixteen_entry_date() {
65 $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
67 if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
68 $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
71 $time_string = sprintf( $time_string,
72 esc_attr( get_the_date( 'c' ) ),
74 esc_attr( get_the_modified_date( 'c' ) ),
75 get_the_modified_date()
78 printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>',
79 _x( 'Posted on', 'Used before publish date.', 'twentysixteen' ),
80 esc_url( get_permalink() ),
86 if ( ! function_exists( 'twentysixteen_entry_taxonomies' ) ) :
88 * Prints HTML with category and tags for current post.
90 * Create your own twentysixteen_entry_taxonomies() function to override in a child theme.
92 * @since Twenty Sixteen 1.0
94 function twentysixteen_entry_taxonomies() {
95 $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) );
96 if ( $categories_list && twentysixteen_categorized_blog() ) {
97 printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
98 _x( 'Categories', 'Used before category names.', 'twentysixteen' ),
103 $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) );
105 printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
106 _x( 'Tags', 'Used before tag names.', 'twentysixteen' ),
113 if ( ! function_exists( 'twentysixteen_post_thumbnail' ) ) :
115 * Displays an optional post thumbnail.
117 * Wraps the post thumbnail in an anchor element on index views, or a div
118 * element when on single views.
120 * Create your own twentysixteen_post_thumbnail() function to override in a child theme.
122 * @since Twenty Sixteen 1.0
124 function twentysixteen_post_thumbnail() {
125 if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
129 if ( is_singular() ) :
132 <div class="post-thumbnail">
133 <?php the_post_thumbnail(); ?>
134 </div><!-- .post-thumbnail -->
138 <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
139 <?php the_post_thumbnail( 'post-thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) ); ?>
142 <?php endif; // End is_singular()
146 if ( ! function_exists( 'twentysixteen_excerpt' ) ) :
148 * Displays the optional excerpt.
150 * Wraps the excerpt in a div element.
152 * Create your own twentysixteen_excerpt() function to override in a child theme.
154 * @since Twenty Sixteen 1.0
156 * @param string $class Optional. Class string of the div element. Defaults to 'entry-summary'.
158 function twentysixteen_excerpt( $class = 'entry-summary' ) {
159 $class = esc_attr( $class );
161 if ( has_excerpt() || is_search() ) : ?>
162 <div class="<?php echo $class; ?>">
163 <?php the_excerpt(); ?>
164 </div><!-- .<?php echo $class; ?> -->
169 if ( ! function_exists( 'twentysixteen_excerpt_more' ) && ! is_admin() ) :
171 * Replaces "[...]" (appended to automatically generated excerpts) with ... and
172 * a 'Continue reading' link.
174 * Create your own twentysixteen_excerpt_more() function to override in a child theme.
176 * @since Twenty Sixteen 1.0
178 * @return string 'Continue reading' link prepended with an ellipsis.
180 function twentysixteen_excerpt_more() {
181 $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
182 esc_url( get_permalink( get_the_ID() ) ),
183 /* translators: %s: Name of current post */
184 sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ), get_the_title( get_the_ID() ) )
186 return ' … ' . $link;
188 add_filter( 'excerpt_more', 'twentysixteen_excerpt_more' );
191 if ( ! function_exists( 'twentysixteen_categorized_blog' ) ) :
193 * Determines whether blog/site has more than one category.
195 * Create your own twentysixteen_categorized_blog() function to override in a child theme.
197 * @since Twenty Sixteen 1.0
199 * @return bool True if there is more than one category, false otherwise.
201 function twentysixteen_categorized_blog() {
202 if ( false === ( $all_the_cool_cats = get_transient( 'twentysixteen_categories' ) ) ) {
203 // Create an array of all the categories that are attached to posts.
204 $all_the_cool_cats = get_categories( array(
206 // We only need to know if there is more than one category.
210 // Count the number of categories that are attached to the posts.
211 $all_the_cool_cats = count( $all_the_cool_cats );
213 set_transient( 'twentysixteen_categories', $all_the_cool_cats );
216 if ( $all_the_cool_cats > 1 ) {
217 // This blog has more than 1 category so twentysixteen_categorized_blog should return true.
220 // This blog has only 1 category so twentysixteen_categorized_blog should return false.
227 * Flushes out the transients used in twentysixteen_categorized_blog().
229 * @since Twenty Sixteen 1.0
231 function twentysixteen_category_transient_flusher() {
232 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
235 // Like, beat it. Dig?
236 delete_transient( 'twentysixteen_categories' );
238 add_action( 'edit_category', 'twentysixteen_category_transient_flusher' );
239 add_action( 'save_post', 'twentysixteen_category_transient_flusher' );
241 if ( ! function_exists( 'twentysixteen_the_custom_logo' ) ) :
243 * Displays the optional custom logo.
245 * Does nothing if the custom logo is not available.
247 * @since Twenty Sixteen 1.2
249 function twentysixteen_the_custom_logo() {
250 if ( function_exists( 'the_custom_logo' ) ) {