]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/themes/twentysixteen/inc/template-tags.php
WordPress 4.7.2-scripts
[autoinstalls/wordpress.git] / wp-content / themes / twentysixteen / inc / template-tags.php
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( '<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' ) ) ),
27                         get_the_author()
28                 );
29         }
30
31         if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
32                 twentysixteen_entry_date();
33         }
34
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 )
41                 );
42         }
43
44         if ( 'post' === get_post_type() ) {
45                 twentysixteen_entry_taxonomies();
46         }
47
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() ) );
51                 echo '</span>';
52         }
53 }
54 endif;
55
56 if ( ! function_exists( 'twentysixteen_entry_date' ) ) :
57 /**
58  * Prints HTML with date information for current post.
59  *
60  * Create your own twentysixteen_entry_date() function to override in a child theme.
61  *
62  * @since Twenty Sixteen 1.0
63  */
64 function twentysixteen_entry_date() {
65         $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
66
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>';
69         }
70
71         $time_string = sprintf( $time_string,
72                 esc_attr( get_the_date( 'c' ) ),
73                 get_the_date(),
74                 esc_attr( get_the_modified_date( 'c' ) ),
75                 get_the_modified_date()
76         );
77
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() ),
81                 $time_string
82         );
83 }
84 endif;
85
86 if ( ! function_exists( 'twentysixteen_entry_taxonomies' ) ) :
87 /**
88  * Prints HTML with category and tags for current post.
89  *
90  * Create your own twentysixteen_entry_taxonomies() function to override in a child theme.
91  *
92  * @since Twenty Sixteen 1.0
93  */
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' ),
99                         $categories_list
100                 );
101         }
102
103         $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentysixteen' ) );
104         if ( $tags_list ) {
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' ),
107                         $tags_list
108                 );
109         }
110 }
111 endif;
112
113 if ( ! function_exists( 'twentysixteen_post_thumbnail' ) ) :
114 /**
115  * Displays an optional post thumbnail.
116  *
117  * Wraps the post thumbnail in an anchor element on index views, or a div
118  * element when on single views.
119  *
120  * Create your own twentysixteen_post_thumbnail() function to override in a child theme.
121  *
122  * @since Twenty Sixteen 1.0
123  */
124 function twentysixteen_post_thumbnail() {
125         if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
126                 return;
127         }
128
129         if ( is_singular() ) :
130         ?>
131
132         <div class="post-thumbnail">
133                 <?php the_post_thumbnail(); ?>
134         </div><!-- .post-thumbnail -->
135
136         <?php else : ?>
137
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' ) ) ); ?>
140         </a>
141
142         <?php endif; // End is_singular()
143 }
144 endif;
145
146 if ( ! function_exists( 'twentysixteen_excerpt' ) ) :
147         /**
148          * Displays the optional excerpt.
149          *
150          * Wraps the excerpt in a div element.
151          *
152          * Create your own twentysixteen_excerpt() function to override in a child theme.
153          *
154          * @since Twenty Sixteen 1.0
155          *
156          * @param string $class Optional. Class string of the div element. Defaults to 'entry-summary'.
157          */
158         function twentysixteen_excerpt( $class = 'entry-summary' ) {
159                 $class = esc_attr( $class );
160
161                 if ( has_excerpt() || is_search() ) : ?>
162                         <div class="<?php echo $class; ?>">
163                                 <?php the_excerpt(); ?>
164                         </div><!-- .<?php echo $class; ?> -->
165                 <?php endif;
166         }
167 endif;
168
169 if ( ! function_exists( 'twentysixteen_excerpt_more' ) && ! is_admin() ) :
170 /**
171  * Replaces "[...]" (appended to automatically generated excerpts) with ... and
172  * a 'Continue reading' link.
173  *
174  * Create your own twentysixteen_excerpt_more() function to override in a child theme.
175  *
176  * @since Twenty Sixteen 1.0
177  *
178  * @return string 'Continue reading' link prepended with an ellipsis.
179  */
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() ) )
185         );
186         return ' &hellip; ' . $link;
187 }
188 add_filter( 'excerpt_more', 'twentysixteen_excerpt_more' );
189 endif;
190
191 if ( ! function_exists( 'twentysixteen_categorized_blog' ) ) :
192 /**
193  * Determines whether blog/site has more than one category.
194  *
195  * Create your own twentysixteen_categorized_blog() function to override in a child theme.
196  *
197  * @since Twenty Sixteen 1.0
198  *
199  * @return bool True if there is more than one category, false otherwise.
200  */
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(
205                         'fields'     => 'ids',
206                         // We only need to know if there is more than one category.
207                         'number'     => 2,
208                 ) );
209
210                 // Count the number of categories that are attached to the posts.
211                 $all_the_cool_cats = count( $all_the_cool_cats );
212
213                 set_transient( 'twentysixteen_categories', $all_the_cool_cats );
214         }
215
216         if ( $all_the_cool_cats > 1 ) {
217                 // This blog has more than 1 category so twentysixteen_categorized_blog should return true.
218                 return true;
219         } else {
220                 // This blog has only 1 category so twentysixteen_categorized_blog should return false.
221                 return false;
222         }
223 }
224 endif;
225
226 /**
227  * Flushes out the transients used in twentysixteen_categorized_blog().
228  *
229  * @since Twenty Sixteen 1.0
230  */
231 function twentysixteen_category_transient_flusher() {
232         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
233                 return;
234         }
235         // Like, beat it. Dig?
236         delete_transient( 'twentysixteen_categories' );
237 }
238 add_action( 'edit_category', 'twentysixteen_category_transient_flusher' );
239 add_action( 'save_post',     'twentysixteen_category_transient_flusher' );
240
241 if ( ! function_exists( 'twentysixteen_the_custom_logo' ) ) :
242 /**
243  * Displays the optional custom logo.
244  *
245  * Does nothing if the custom logo is not available.
246  *
247  * @since Twenty Sixteen 1.2
248  */
249 function twentysixteen_the_custom_logo() {
250         if ( function_exists( 'the_custom_logo' ) ) {
251                 the_custom_logo();
252         }
253 }
254 endif;