]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/post-thumbnail-template.php
Wordpress 2.9
[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 (true) or not (false).
19  */
20 function has_post_thumbnail( $post_id = NULL ) {
21         global $id;
22         $post_id = ( NULL === $post_id ) ? $id : $post_id;
23         return !! get_post_thumbnail_id( $post_id );
24 }
25
26 /**
27  * Retrieve Post Thumbnail ID.
28  * 
29  * @since 2.9.0
30  *
31  * @param int $post_id Optional. Post ID.
32  * @return int
33  */
34 function get_post_thumbnail_id( $post_id = NULL ) {
35         global $id;
36         $post_id = ( NULL === $post_id ) ? $id : $post_id;
37         return get_post_meta( $post_id, '_thumbnail_id', true );
38 }
39
40 /**
41  * Display Post Thumbnail.
42  * 
43  * @since 2.9.0
44  *
45  * @param int $size Optional. Image size.  Defaults to 'post-thumbnail', which theme sets using set_post_thumbnail_size( $width, $height, $crop_flag );.
46  * @param string|array $attr Optional. Query string or array of attributes.
47  */
48 function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) {
49         echo get_the_post_thumbnail( NULL, $size, $attr );
50 }
51
52 /**
53  * Retrieve Post Thumbnail.
54  * 
55  * @since 2.9.0
56  *
57  * @param int $post_id Optional. Post ID.
58  * @param string $size Optional. Image size.  Defaults to 'thumbnail'.
59  * @param string|array $attr Optional. Query string or array of attributes.
60   */
61 function get_the_post_thumbnail( $post_id = NULL, $size = 'post-thumbnail', $attr = '' ) {
62         global $id;
63         $post_id = ( NULL === $post_id ) ? $id : $post_id;
64         $post_thumbnail_id = get_post_thumbnail_id( $post_id );
65         $size = apply_filters( 'post_thumbnail_size', $size );
66         if ( $post_thumbnail_id ) {
67                 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
68                 $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
69                 do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
70         } else {
71                 $html = '';
72         }
73         return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
74 }
75
76 ?>