Ticket #15447: 15447.3.diff
| File 15447.3.diff, 1.7 KB (added by scribu, 2 years ago) |
|---|
-
wp-includes/post-thumbnail-template.php
48 48 } 49 49 50 50 /** 51 * Update cache for thumbnails in current loop 52 * 53 * @since 3.2 54 */ 55 function update_thumbnail_cache() { 56 global $wp_query; 57 58 // return if not at loop start 59 if ( 0 != $wp_query->current_post ) 60 return; 61 62 $thumb_ids = array(); 63 foreach ( $wp_query->posts as $post ) { 64 if ( $id = get_post_thumbnail_id( $post->ID ) ) 65 $thumb_ids[] = $id; 66 } 67 68 if ( ! empty( $thumb_ids ) ) { 69 get_posts( array( 70 'update_post_term_cache' => false, 71 'include' => $thumb_ids, 72 'post_type' => 'attachment', 73 'post_status' => 'inherit', 74 'nopaging' => true, 75 ) ); 76 } 77 } 78 79 /** 51 80 * Retrieve Post Thumbnail. 52 81 * 53 82 * @since 2.9.0 … … 57 86 * @param string|array $attr Optional. Query string or array of attributes. 58 87 */ 59 88 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) { 89 if ( in_the_loop() ) 90 update_thumbnail_cache(); 91 60 92 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; 61 93 $post_thumbnail_id = get_post_thumbnail_id( $post_id ); 62 94 $size = apply_filters( 'post_thumbnail_size', $size ); 63 95 if ( $post_thumbnail_id ) { 64 96 do_action( 'begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters 97 65 98 $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); 66 99 do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); 67 100 } else {
