| 1 | diff --git wp-includes/post-thumbnail-template.php wp-includes/post-thumbnail-template.php |
|---|
| 2 | index 3758d1d..f1c897a 100644 |
|---|
| 3 | --- wp-includes/post-thumbnail-template.php |
|---|
| 4 | +++ wp-includes/post-thumbnail-template.php |
|---|
| 5 | @@ -48,6 +48,39 @@ function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { |
|---|
| 6 | } |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | + * Update cache for thumbnails in current loop |
|---|
| 10 | + * |
|---|
| 11 | + * @since 3.2 |
|---|
| 12 | + */ |
|---|
| 13 | +function update_thumbnail_cache() { |
|---|
| 14 | + global $wp_query; |
|---|
| 15 | + |
|---|
| 16 | + // return if this loop is already cached |
|---|
| 17 | + if ( empty( $wp_query->_thumbnails_cached ) ) |
|---|
| 18 | + return; |
|---|
| 19 | + |
|---|
| 20 | + $thumb_ids = array(); |
|---|
| 21 | + foreach ( $wp_query->posts as $post ) { |
|---|
| 22 | + if ( $id = get_post_thumbnail_id( $post->ID ) ) |
|---|
| 23 | + $thumb_ids[] = $id; |
|---|
| 24 | + } |
|---|
| 25 | + |
|---|
| 26 | + if ( ! empty( $thumb_ids ) ) { |
|---|
| 27 | + $thumb_ids = array_filter( array_unique( $thumb_ids ) ); |
|---|
| 28 | + |
|---|
| 29 | + get_posts( array( |
|---|
| 30 | + 'update_post_term_cache' => false, |
|---|
| 31 | + 'include' => $thumb_ids, |
|---|
| 32 | + 'post_type' => 'attachment', |
|---|
| 33 | + 'post_status' => 'inherit', |
|---|
| 34 | + 'nopaging' => true, |
|---|
| 35 | + ) ); |
|---|
| 36 | + } |
|---|
| 37 | + |
|---|
| 38 | + $wp_query->_thumbnails_cached = true; |
|---|
| 39 | +} |
|---|
| 40 | + |
|---|
| 41 | +/** |
|---|
| 42 | * Retrieve Post Thumbnail. |
|---|
| 43 | * |
|---|
| 44 | * @since 2.9.0 |
|---|
| 45 | @@ -62,6 +95,10 @@ function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $att |
|---|
| 46 | $size = apply_filters( 'post_thumbnail_size', $size ); |
|---|
| 47 | if ( $post_thumbnail_id ) { |
|---|
| 48 | 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 |
|---|
| 49 | + |
|---|
| 50 | + if ( in_the_loop() ) |
|---|
| 51 | + update_thumbnail_cache(); |
|---|
| 52 | + |
|---|
| 53 | $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); |
|---|
| 54 | do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); |
|---|
| 55 | } else { |
|---|