| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom template tags for this theme. 4 * 5 * Eventually, some of the functionality here could be replaced by core features. 6 * 7 * @package WordPress 8 * @subpackage Twenty_Seventeen 9 * @since Twenty Seventeen 1.0 10 */ 11 12 if ( ! function_exists( 'twentyseventeen_posted_on' ) ) : 13 /** 14 * Prints HTML with meta information for the current post-date/time and author. 15 */ 16 function twentyseventeen_posted_on() { 17 18 // Get the author name; wrap it in a link. 19 $byline = sprintf( 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>' 23 ); 24 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>'; 27 } 28 endif; 29 30 31 if ( ! function_exists( 'twentyseventeen_time_link' ) ) : 32 /** 33 * Gets a nicely formatted string for the published date. 34 */ 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>'; 39 } 40 41 $time_string = sprintf( 42 $time_string, 43 get_the_date( DATE_W3C ), 44 get_the_date(), 45 get_the_modified_date( DATE_W3C ), 46 get_the_modified_date() 47 ); 48 49 // Wrap the time string in a link, and preface it with 'Posted on'. 50 return sprintf( 51 /* translators: %s: Post date. */ 52 __( '<span class="screen-reader-text">Posted on</span> %s', 'twentyseventeen' ), 53 '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>' 54 ); 55 } 56 endif; 57 58 59 if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) : 60 /** 61 * Prints HTML with meta information for the categories, tags and comments. 62 */ 63 function twentyseventeen_entry_footer() { 64 65 $separate_meta = wp_get_list_item_separator(); 66 67 // Get Categories for posts. 68 $categories_list = get_the_category_list( $separate_meta ); 69 70 // Get Tags for posts. 71 $tags_list = get_the_tag_list( '', $separate_meta ); 72 73 // We don't want to output .entry-footer if it will be empty, so make sure it is not. 74 if ( ( ( twentyseventeen_categorized_blog() && $categories_list ) || $tags_list ) || get_edit_post_link() ) { 75 76 echo '<footer class="entry-footer">'; 77 78 if ( 'post' === get_post_type() ) { 79 if ( ( $categories_list && twentyseventeen_categorized_blog() ) || $tags_list ) { 80 echo '<span class="cat-tags-links">'; 81 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' ) ) . 85 /* translators: Hidden accessibility text. */ 86 '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . 87 $categories_list . 88 '</span>'; 89 } 90 91 if ( $tags_list && ! is_wp_error( $tags_list ) ) { 92 echo '<span class="tags-links">' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . 93 /* translators: Hidden accessibility text. */ 94 '<span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . 95 $tags_list . 96 '</span>'; 97 } 98 99 echo '</span>'; 100 } 101 } 102 103 twentyseventeen_edit_link(); 104 105 echo '</footer> <!-- .entry-footer -->'; 106 } 107 } 108 endif; 109 110 111 if ( ! function_exists( 'twentyseventeen_edit_link' ) ) : 112 /** 113 * Displays an accessibility-friendly link to edit a post or page. 114 * 115 * @since Twenty Seventeen 1.0 116 * @since Twenty Seventeen 4.1 Added `$post_id` parameter. 117 * 118 * @param int $post_id Post ID. Default 0. 119 */ 120 function twentyseventeen_edit_link( $post_id = 0 ) { 121 edit_post_link( 122 sprintf( 123 /* translators: %s: Post title. Only visible to screen readers. */ 124 __( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), 125 get_the_title( $post_id ) 126 ), 127 '<span class="edit-link">', 128 '</span>', 129 $post_id 130 ); 131 } 132 endif; 133 134 /** 135 * Displays a front page section. 136 * 137 * @global int|string $twentyseventeencounter Front page section counter. 138 * @global WP_Post $post Global post object. 139 * 140 * @param WP_Customize_Partial $partial Partial associated with a selective refresh request. 141 * @param int $id Front page section to display. 142 */ 143 function twentyseventeen_front_page_section( $partial = null, $id = 0 ) { 144 if ( $partial instanceof WP_Customize_Partial ) { 145 // Find out the ID and set it up during a selective refresh. 146 global $twentyseventeencounter; 147 148 $id = str_replace( 'panel_', '', $partial->id ); 149 150 $twentyseventeencounter = $id; 151 } 152 153 // Only when in Customizer, use a placeholder for an empty panel. 154 $show_panel_placeholder = false; 155 156 global $post; // Modify the global post object before setting up post data. 157 if ( get_theme_mod( 'panel_' . $id ) ) { 158 $post = get_post( get_theme_mod( 'panel_' . $id ) ); 159 setup_postdata( $post ); 160 set_query_var( 'panel', $id ); 161 162 if ( $post && in_array( $post->post_status, array( 'publish', 'private' ), true ) ) { 163 get_template_part( 'template-parts/page/content', 'front-page-panels' ); 164 } elseif ( is_customize_preview() ) { 165 $show_panel_placeholder = true; 166 } 167 168 wp_reset_postdata(); 169 } elseif ( is_customize_preview() ) { 170 $show_panel_placeholder = true; 171 } 172 173 if ( $show_panel_placeholder ) { 174 // The output placeholder anchor. 175 printf( 176 '<article class="panel-placeholder panel twentyseventeen-panel twentyseventeen-panel%1$s" id="panel%1$s">' . 177 '<span class="twentyseventeen-panel-title">%2$s</span></article>', 178 $id, 179 /* translators: %s: The section ID. */ 180 sprintf( __( 'Front Page Section %s Placeholder', 'twentyseventeen' ), $id ) 181 ); 182 } 183 } 184 185 /** 186 * Returns true if a blog has more than 1 category. 187 * 188 * @return bool Whether the blog has more than 1 category. 189 */ 190 function twentyseventeen_categorized_blog() { 191 $category_count = get_transient( 'twentyseventeen_categories' ); 192 193 if ( false === $category_count ) { 194 // Create an array of all the categories that are attached to posts. 195 $categories = get_categories( 196 array( 197 'fields' => 'ids', 198 'hide_empty' => 1, 199 // We only need to know if there is more than one category. 200 'number' => 2, 201 ) 202 ); 203 204 // Count the number of categories that are attached to the posts. 205 $category_count = count( $categories ); 206 207 set_transient( 'twentyseventeen_categories', $category_count ); 208 } 209 210 // Allow viewing case of 0 or 1 categories in post preview. 211 if ( is_preview() ) { 212 return true; 213 } 214 215 return $category_count > 1; 216 } 217 218 219 /** 220 * Flushes out the transients used in twentyseventeen_categorized_blog. 221 */ 222 function twentyseventeen_category_transient_flusher() { 223 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 224 return; 225 } 226 // Like, beat it. Dig? 227 delete_transient( 'twentyseventeen_categories' ); 228 } 229 add_action( 'edit_category', 'twentyseventeen_category_transient_flusher' ); 230 add_action( 'save_post', 'twentyseventeen_category_transient_flusher' ); 231 232 if ( ! function_exists( 'wp_body_open' ) ) : 233 /** 234 * Fires the wp_body_open action. 235 * 236 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 237 * 238 * @since Twenty Seventeen 2.2 239 */ 240 function wp_body_open() { 241 /** 242 * Fires after the opening <body> tag. 243 * 244 * @since Twenty Seventeen 2.2 245 */ 246 do_action( 'wp_body_open' ); 247 } 248 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Jul 22 08:20:19 2026 | Cross-referenced by PHPXref |