The_post_thumbnail
The_post_thumbnail is mainly used in WordPress to print the thumbnails set in the article, and the Get_the_post_thumbnail function can return the HTML code you need as a string.
The use of The_post_thumbnail functions
The_post_thumbnail ($size, $attr)
function arguments
- $size refers to the type of thumbnail you want. The default is ' Post-thumbnail ', which is the featured image.
- $attr the property settings in the image img tag.
the_post_thumbnail function Declaration
/** * Display Post Thumbnail. * * @since 2.9.0 * * @param int $size Optional. Image size.
Defaults to ' Post-thumbnail ', which theme sets using Set_post_thumbnail_size ($width, $height, $crop _flag);. * @param string|array $attr Optional.
Query string or array of attributes. */function The_post_thumbnail ($size = ' Post-thumbnail ', $attr = ') {echo get_the_post_thumbnail (null, $size, $attr
);
get_the_post_thumbnail function declaration * Retrieve post thumbnail. * * @since 2.9.0 * * @param int $post _id Optional.
Post ID. * @param string $size Optional. Image size.
Defaults to ' Post-thumbnail '. * @param string|array $attr Optional.
Query string or array of attributes. * * Function get_the_post_thumbnail ($post _id = null, $size = ' Post-thumbnail ', $attr = ') {$post _id = (Null = = = _id)?
GET_THE_ID (): $post _id;
$post _thumbnail_id = get_post_thumbnail_id ($post _id);
$size = apply_filters (' post_thumbnail_size ', $size); if ($post _thumbnail_id) {do_action (' Begin_feTch_post_thumbnail_html ', $post _id, $post _thumbnail_id, $size); For "Just in" filtering of all of Wp_get_attachment_image () ' s filters if (In_the_loop ()) Update_post_thumbnai
L_cache ();
$html = Wp_get_attachment_image ($post _thumbnail_id, $size, False, $attr);
Do_action (' end_fetch_post_thumbnail_html ', $post _id, $post _thumbnail_id, $size);
else {$html = ';
Return apply_filters (' post_thumbnail_html ', $html, $post _id, $post _thumbnail_id, $size, $attr);
Set_post_thumbnail_size
the Set_post_thumbnail_size function is a function of setting the feature image size in WordPress is also a simple application of the Add_image_size function. In order to better highlight the use of feature images, WordPress since the 2.9.0 version of the beginning, it has the function.
The use of Set_post_thumbnail_size functions
Probably similar to the Add_image_size function, except that the function is set only for featured images.
Set_post_thumbnail_size ($width, $height, $crop)
Parameter detailed
- $width Image Width
- $height Image Height
- $crop Trim the image by width
Instance
Set_post_thumbnail_size (100,0,true);
Note: When the height and width of any one of 0 o'clock, WP will automatically adapt to another value for thumbnail generation work.
function declaration
/**
* Registers a image size for the post thumbnail
*
* @since 2.9.0
/
function Set_post_thumbnail_ Size ($width = 0, $height = 0, $crop = False) {
add_image_size (' Post-thumbnail ', $width, $height, $crop);