3 * Custom template tags for this theme
5 * Eventually, some of the functionality here could be replaced by core features.
8 * @subpackage Twenty_Seventeen
12 if ( ! function_exists( 'twentyseventeen_posted_on' ) ) :
14 * Prints HTML with meta information for the current post-date/time and author.
16 function twentyseventeen_posted_on() {
18 // Get the author name; wrap it in a link.
20 /* translators: %s: post author */
21 __( 'by %s', 'twentyseventeen' ),
22 '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . get_the_author() . '</a></span>'
25 // Finally, let's write all of this to the page.
26 echo '<span class="posted-on">' . twentyseventeen_time_link() . '</span><span class="byline"> ' . $byline . '</span>';
31 if ( ! function_exists( 'twentyseventeen_time_link' ) ) :
33 * Gets a nicely formatted string for the published date.
35 function twentyseventeen_time_link() {
36 $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
37 if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
38 $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
41 $time_string = sprintf( $time_string,
42 get_the_date( DATE_W3C ),
44 get_the_modified_date( DATE_W3C ),
45 get_the_modified_date()
48 // Wrap the time string in a link, and preface it with 'Posted on'.
50 /* translators: %s: post date */
51 __( '<span class="screen-reader-text">Posted on</span> %s', 'twentyseventeen' ),
52 '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
58 if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) :
60 * Prints HTML with meta information for the categories, tags and comments.
62 function twentyseventeen_entry_footer() {
64 /* translators: used between list items, there is a space after the comma */
65 $separate_meta = __( ', ', 'twentyseventeen' );
67 // Get Categories for posts.
68 $categories_list = get_the_category_list( $separate_meta );
70 // Get Tags for posts.
71 $tags_list = get_the_tag_list( '', $separate_meta );
73 // We don't want to output .entry-footer if it will be empty, so make sure its not.
74 if ( ( ( twentyseventeen_categorized_blog() && $categories_list ) || $tags_list ) || get_edit_post_link() ) {
76 echo '<footer class="entry-footer">';
78 if ( 'post' === get_post_type() ) {
79 if ( ( $categories_list && twentyseventeen_categorized_blog() ) || $tags_list ) {
80 echo '<span class="cat-tags-links">';
82 // Make sure there's more than one category before displaying.
83 if ( $categories_list && twentyseventeen_categorized_blog() ) {
84 echo '<span class="cat-links">' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>';
88 echo '<span class="tags-links">' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . '<span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . $tags_list . '</span>';
95 twentyseventeen_edit_link();
97 echo '</footer> <!-- .entry-footer -->';
103 if ( ! function_exists( 'twentyseventeen_edit_link' ) ) :
105 * Returns an accessibility-friendly link to edit a post or page.
107 * This also gives us a little context about what exactly we're editing
108 * (post or page?) so that users understand a bit more where they are in terms
109 * of the template hierarchy and their content. Helpful when/if the single-page
110 * layout with multiple posts/pages shown gets confusing.
112 function twentyseventeen_edit_link() {
114 $link = edit_post_link(
116 /* translators: %s: Name of current post */
117 __( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
120 '<span class="edit-link">',
129 * Display a front page section.
131 * @param $partial WP_Customize_Partial Partial associated with a selective refresh request.
132 * @param $id integer Front page section to display.
134 function twentyseventeen_front_page_section( $partial = null, $id = 0 ) {
135 if ( is_a( $partial, 'WP_Customize_Partial' ) ) {
136 // Find out the id and set it up during a selective refresh.
137 global $twentyseventeencounter;
138 $id = str_replace( 'panel_', '', $partial->id );
139 $twentyseventeencounter = $id;
142 global $post; // Modify the global post object before setting up post data.
143 if ( get_theme_mod( 'panel_' . $id ) ) {
145 $post = get_post( get_theme_mod( 'panel_' . $id ) );
146 setup_postdata( $post );
147 set_query_var( 'panel', $id );
149 get_template_part( 'template-parts/page/content', 'front-page-panels' );
152 } elseif ( is_customize_preview() ) {
153 // The output placeholder anchor.
154 echo '<article class="panel-placeholder panel twentyseventeen-panel twentyseventeen-panel' . $id . '" id="panel' . $id . '"><span class="twentyseventeen-panel-title">' . sprintf( __( 'Front Page Section %1$s Placeholder', 'twentyseventeen' ), $id ) . '</span></article>';
159 * Returns true if a blog has more than 1 category.
163 function twentyseventeen_categorized_blog() {
164 $category_count = get_transient( 'twentyseventeen_categories' );
166 if ( false === $category_count ) {
167 // Create an array of all the categories that are attached to posts.
168 $categories = get_categories( array(
171 // We only need to know if there is more than one category.
175 // Count the number of categories that are attached to the posts.
176 $category_count = count( $categories );
178 set_transient( 'twentyseventeen_categories', $category_count );
181 return $category_count > 1;
186 * Flush out the transients used in twentyseventeen_categorized_blog.
188 function twentyseventeen_category_transient_flusher() {
189 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
192 // Like, beat it. Dig?
193 delete_transient( 'twentyseventeen_categories' );
195 add_action( 'edit_category', 'twentyseventeen_category_transient_flusher' );
196 add_action( 'save_post', 'twentyseventeen_category_transient_flusher' );