33 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; |
33 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; |
34 return get_post_meta( $post_id, '_thumbnail_id', true ); |
34 return get_post_meta( $post_id, '_thumbnail_id', true ); |
35 } |
35 } |
36 |
36 |
37 /** |
37 /** |
38 * Display Post Thumbnail. |
38 * Display the post thumbnail. |
|
39 * |
|
40 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size |
|
41 * is registered, which differs from the 'thumbnail' image size managed via the |
|
42 * Settings > Media screen. |
|
43 * |
|
44 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image |
|
45 * size is used by default, though a different size can be specified instead as needed. |
39 * |
46 * |
40 * @since 2.9.0 |
47 * @since 2.9.0 |
41 * |
48 * |
42 * @param string|array $size Optional. Image size. Defaults to 'post-thumbnail', which theme sets using set_post_thumbnail_size( $width, $height, $crop_flag );. |
49 * @see get_the_post_thumbnail() |
43 * @param string|array $attr Optional. Query string or array of attributes. |
50 * |
|
51 * @param string|array $size Optional. Registered image size to use, or flat array of height |
|
52 * and width values. Default 'post-thumbnail'. |
|
53 * @param string|array $attr Optional. Query string or array of attributes. Default empty. |
44 */ |
54 */ |
45 function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { |
55 function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { |
46 echo get_the_post_thumbnail( null, $size, $attr ); |
56 echo get_the_post_thumbnail( null, $size, $attr ); |
47 } |
57 } |
48 |
58 |
49 /** |
59 /** |
50 * Update cache for thumbnails in the current loop |
60 * Update cache for thumbnails in the current loop |
51 * |
61 * |
52 * @since 3.2 |
62 * @since 3.2.0 |
53 * |
63 * |
54 * @param object $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global. |
64 * @param object $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global. |
55 */ |
65 */ |
56 function update_post_thumbnail_cache( $wp_query = null ) { |
66 function update_post_thumbnail_cache( $wp_query = null ) { |
57 if ( ! $wp_query ) |
67 if ( ! $wp_query ) |
72 |
82 |
73 $wp_query->thumbnails_cached = true; |
83 $wp_query->thumbnails_cached = true; |
74 } |
84 } |
75 |
85 |
76 /** |
86 /** |
77 * Retrieve Post Thumbnail. |
87 * Retrieve the post thumbnail. |
|
88 * |
|
89 * When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size |
|
90 * is registered, which differs from the 'thumbnail' image size managed via the |
|
91 * Settings > Media screen. |
|
92 * |
|
93 * When using the_post_thumbnail() or related functions, the 'post-thumbnail' image |
|
94 * size is used by default, though a different size can be specified instead as needed. |
78 * |
95 * |
79 * @since 2.9.0 |
96 * @since 2.9.0 |
80 * |
97 * |
81 * @param int $post_id Optional. Post ID. |
98 * @param int $post_id Post ID. Default is the ID of the `$post` global. |
82 * @param string $size Optional. Image size. Defaults to 'post-thumbnail'. |
99 * @param string|array $size Optional. Registered image size to use, or flat array of height |
83 * @param string|array $attr Optional. Query string or array of attributes. |
100 * and width values. Default 'post-thumbnail'. |
|
101 * @param string|array $attr Optional. Query string or array of attributes. Default empty. |
84 */ |
102 */ |
85 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) { |
103 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) { |
86 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; |
104 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; |
87 $post_thumbnail_id = get_post_thumbnail_id( $post_id ); |
105 $post_thumbnail_id = get_post_thumbnail_id( $post_id ); |
88 |
106 |