[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom template tags for Twenty Fifteen 4 * 5 * Eventually, some of the functionality here could be replaced by core features. 6 * 7 * @package WordPress 8 * @subpackage Twenty_Fifteen 9 * @since Twenty Fifteen 1.0 10 */ 11 12 if ( ! function_exists( 'twentyfifteen_comment_nav' ) ) : 13 /** 14 * Display navigation to next/previous comments when applicable. 15 * 16 * @since Twenty Fifteen 1.0 17 */ 18 function twentyfifteen_comment_nav() { 19 // Are there comments to navigate through? 20 if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : 21 ?> 22 <nav class="navigation comment-navigation"> 23 <h2 class="screen-reader-text"><?php _e( 'Comment navigation', 'twentyfifteen' ); ?></h2> 24 <div class="nav-links"> 25 <?php 26 $prev_link = get_previous_comments_link( __( 'Older Comments', 'twentyfifteen' ) ); 27 if ( $prev_link ) { 28 printf( '<div class="nav-previous">%s</div>', $prev_link ); 29 } 30 31 $next_link = get_next_comments_link( __( 'Newer Comments', 'twentyfifteen' ) ); 32 if ( $next_link ) { 33 printf( '<div class="nav-next">%s</div>', $next_link ); 34 } 35 ?> 36 </div><!-- .nav-links --> 37 </nav><!-- .comment-navigation --> 38 <?php 39 endif; 40 } 41 endif; 42 43 if ( ! function_exists( 'twentyfifteen_entry_meta' ) ) : 44 /** 45 * Prints HTML with meta information for the categories, tags. 46 * 47 * @since Twenty Fifteen 1.0 48 */ 49 function twentyfifteen_entry_meta() { 50 if ( is_sticky() && is_home() && ! is_paged() ) { 51 printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'twentyfifteen' ) ); 52 } 53 54 $format = get_post_format(); 55 if ( current_theme_supports( 'post-formats', $format ) ) { 56 printf( 57 '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>', 58 sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ), 59 esc_url( get_post_format_link( $format ) ), 60 get_post_format_string( $format ) 61 ); 62 } 63 64 if ( in_array( get_post_type(), array( 'post', 'attachment' ), true ) ) { 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( 72 $time_string, 73 esc_attr( get_the_date( 'c' ) ), 74 get_the_date(), 75 esc_attr( get_the_modified_date( 'c' ) ), 76 get_the_modified_date() 77 ); 78 79 printf( 80 '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>', 81 _x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ), 82 esc_url( get_permalink() ), 83 $time_string 84 ); 85 } 86 87 if ( 'post' === get_post_type() ) { 88 if ( is_singular() || is_multi_author() ) { 89 printf( 90 '<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>', 91 _x( 'Author', 'Used before post author name.', 'twentyfifteen' ), 92 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), 93 get_the_author() 94 ); 95 } 96 97 $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); 98 if ( $categories_list && twentyfifteen_categorized_blog() ) { 99 printf( 100 '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', 101 _x( 'Categories', 'Used before category names.', 'twentyfifteen' ), 102 $categories_list 103 ); 104 } 105 106 $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); 107 if ( $tags_list && ! is_wp_error( $tags_list ) ) { 108 printf( 109 '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', 110 _x( 'Tags', 'Used before tag names.', 'twentyfifteen' ), 111 $tags_list 112 ); 113 } 114 } 115 116 if ( is_attachment() && wp_attachment_is_image() ) { 117 // Retrieve attachment metadata. 118 $metadata = wp_get_attachment_metadata(); 119 120 printf( 121 '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s × %4$s</a></span>', 122 _x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ), 123 esc_url( wp_get_attachment_url() ), 124 $metadata['width'], 125 $metadata['height'] 126 ); 127 } 128 129 if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { 130 echo '<span class="comments-link">'; 131 /* translators: %s: Post title. Only visible to screen readers. */ 132 comments_popup_link( sprintf( __( 'Leave a comment<span class="screen-reader-text"> on %s</span>', 'twentyfifteen' ), get_the_title() ) ); 133 echo '</span>'; 134 } 135 } 136 endif; 137 138 /** 139 * Determine whether blog/site has more than one category. 140 * 141 * @since Twenty Fifteen 1.0 142 * 143 * @return bool True of there is more than one category, false otherwise. 144 */ 145 function twentyfifteen_categorized_blog() { 146 $all_the_cool_cats = get_transient( 'twentyfifteen_categories' ); 147 if ( false === $all_the_cool_cats ) { 148 // Create an array of all the categories that are attached to posts. 149 $all_the_cool_cats = get_categories( 150 array( 151 'fields' => 'ids', 152 'hide_empty' => 1, 153 154 // We only need to know if there is more than one category. 155 'number' => 2, 156 ) 157 ); 158 159 // Count the number of categories that are attached to the posts. 160 $all_the_cool_cats = count( $all_the_cool_cats ); 161 162 set_transient( 'twentyfifteen_categories', $all_the_cool_cats ); 163 } 164 165 if ( $all_the_cool_cats > 1 || is_preview() ) { 166 // This blog has more than 1 category so twentyfifteen_categorized_blog() should return true. 167 return true; 168 } else { 169 // This blog has only 1 category so twentyfifteen_categorized_blog() should return false. 170 return false; 171 } 172 } 173 174 /** 175 * Flush out the transients used in {@see twentyfifteen_categorized_blog()}. 176 * 177 * @since Twenty Fifteen 1.0 178 */ 179 function twentyfifteen_category_transient_flusher() { 180 // Like, beat it. Dig? 181 delete_transient( 'twentyfifteen_categories' ); 182 } 183 add_action( 'edit_category', 'twentyfifteen_category_transient_flusher' ); 184 add_action( 'save_post', 'twentyfifteen_category_transient_flusher' ); 185 186 if ( ! function_exists( 'twentyfifteen_post_thumbnail' ) ) : 187 /** 188 * Display an optional post thumbnail. 189 * 190 * Wraps the post thumbnail in an anchor element on index views, or a div 191 * element when on single views. 192 * 193 * @since Twenty Fifteen 1.0 194 */ 195 function twentyfifteen_post_thumbnail() { 196 if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) { 197 return; 198 } 199 200 if ( is_singular() ) : 201 ?> 202 203 <div class="post-thumbnail"> 204 <?php the_post_thumbnail(); ?> 205 </div><!-- .post-thumbnail --> 206 207 <?php else : ?> 208 209 <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"> 210 <?php 211 the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) ); 212 ?> 213 </a> 214 215 <?php 216 endif; // End is_singular(). 217 } 218 endif; 219 220 if ( ! function_exists( 'twentyfifteen_get_link_url' ) ) : 221 /** 222 * Return the post URL. 223 * 224 * Falls back to the post permalink if no URL is found in the post. 225 * 226 * @since Twenty Fifteen 1.0 227 * 228 * @see get_url_in_content() 229 * 230 * @return string The Link format URL. 231 */ 232 function twentyfifteen_get_link_url() { 233 $has_url = get_url_in_content( get_the_content() ); 234 235 return $has_url ? $has_url : apply_filters( 'the_permalink', get_permalink() ); 236 } 237 endif; 238 239 if ( ! function_exists( 'twentyfifteen_excerpt_more' ) && ! is_admin() ) : 240 /** 241 * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link. 242 * 243 * @since Twenty Fifteen 1.0 244 * 245 * @return string 'Continue reading' link prepended with an ellipsis. 246 */ 247 function twentyfifteen_excerpt_more( $more ) { 248 $link = sprintf( 249 '<a href="%1$s" class="more-link">%2$s</a>', 250 esc_url( get_permalink( get_the_ID() ) ), 251 /* translators: %s: Post title. Only visible to screen readers. */ 252 sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' ) 253 ); 254 return ' … ' . $link; 255 } 256 add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' ); 257 endif; 258 259 if ( ! function_exists( 'twentyfifteen_the_custom_logo' ) ) : 260 /** 261 * Displays the optional custom logo. 262 * 263 * Does nothing if the custom logo is not available. 264 * 265 * @since Twenty Fifteen 1.5 266 */ 267 function twentyfifteen_the_custom_logo() { 268 if ( function_exists( 'the_custom_logo' ) ) { 269 the_custom_logo(); 270 } 271 } 272 endif; 273 274 if ( ! function_exists( 'wp_body_open' ) ) : 275 /** 276 * Fire the wp_body_open action. 277 * 278 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 279 * 280 * @since Twenty Fifteen 2.5 281 */ 282 function wp_body_open() { 283 /** 284 * Triggered after the opening <body> tag. 285 * 286 * @since Twenty Fifteen 2.5 287 */ 288 do_action( 'wp_body_open' ); 289 } 290 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 |