Debugging thumbnails in WordPress related PHP functions using analytic _php techniques

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.