wp/wp-includes/post-thumbnail-template.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * WordPress Post Thumbnail Template Functions.
     3  * WordPress Post Thumbnail Template Functions.
     4  *
     4  *
     5  * Support for post thumbnails
     5  * Support for post thumbnails.
     6  * Themes function.php must call add_theme_support( 'post-thumbnails' ) to use these.
     6  * Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these.
     7  *
     7  *
     8  * @package WordPress
     8  * @package WordPress
     9  * @subpackage Template
     9  * @subpackage Template
    10  */
    10  */
    11 
    11 
    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