]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/post-thumbnail-template.php
Wordpress 3.1-scripts
[autoinstalls/wordpress.git] / wp-includes / post-thumbnail-template.php
1 <?php
2 /**
3  * WordPress Post Thumbnail Template Functions.
4  *
5  * Support for post thumbnails
6  * Themes function.php must call add_theme_support( 'post-thumbnails' ) to use these.
7  *
8  * @package WordPress
9  * @subpackage Template
10  */
11
12 /**
13  * Check if post has an image attached.
14  *
15  * @since 2.9.0
16  *
17  * @param int $post_id Optional. Post ID.
18  * @return bool Whether post has an image attached.
19  */
20 function has_post_thumbnail( $post_id = null ) {
21         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
22         return (bool) get_post_thumbnail_id( $post_id );
23 }
24
25 /**
26  * Retrieve Post Thumbnail ID.
27  *
28  * @since 2.9.0
29  *
30  * @param int $post_id Optional. Post ID.
31  * @return int
32  */
33 function get_post_thumbnail_id( $post_id = null ) {
34         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
35         return get_post_meta( $post_id, '_thumbnail_id', true );
36 }
37
38 /**
39  * Display Post Thumbnail.
40  *
41  * @since 2.9.0
42  *
43  * @param int $size Optional. Image size.  Defaults to 'post-thumbnail', which theme sets using set_post_thumbnail_size( $width, $height, $crop_flag );.
44  * @param string|array $attr Optional. Query string or array of attributes.
45  */
46 function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) {
47         echo get_the_post_thumbnail( null, $size, $attr );
48 }
49
50 /**
51  * Retrieve Post Thumbnail.
52  *
53  * @since 2.9.0
54  *
55  * @param int $post_id Optional. Post ID.
56  * @param string $size Optional. Image size.  Defaults to 'thumbnail'.
57  * @param string|array $attr Optional. Query string or array of attributes.
58  */
59 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) {
60         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
61         $post_thumbnail_id = get_post_thumbnail_id( $post_id );
62         $size = apply_filters( 'post_thumbnail_size', $size );
63         if ( $post_thumbnail_id ) {
64                 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
65                 $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
66                 do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
67         } else {
68                 $html = '';
69         }
70         return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
71 }
72
73 ?>