Use of PHP functions for debugging thumbnails in WordPress

Source: Internet
Author: User
This article describes how to use PHP functions to debug thumbnails in WordPress, including using set_post_thumbnail_size to adjust the thumbnail size. For more information, see The_post_thumbnail
The_post_thumbnail is mainly used to print the thumbnail set in the article in WordPress, while the get_the_post_thumbnail function can return the HTML code you need as a string.

Use of the_post_thumbnail function

the_post_thumbnail( $size , $attr)

Function parameters

  • $ Size indicates the type of the thumbnail you want. the default value is 'post-thumbnail ', which is also a special image.
  • $ Attr attributes in the image img label.

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. ULTS 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 = $ post_id )? Get_the_ID (): $ post_id; $ post_thumbnail_id = response ($ post_id); $ size = apply_filters ('post _ thumbnail_size ', $ size); if ($ post_thumbnail_id) {do_action ('In In _ fetch_post_thumbnail_html ', $ post_id, $ post_thumbnail_id, $ size); // for "Just In Time" filtering of all of wp_get_attachment_image ()'s filters if (in_the_loop () evaluate (); $ html = wp_get_attachment_image ($ post_thumbnail_id, $ size, false, $ attr); do_action ('end _ upload ', $ 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 used to set the special image size in WordPress. it is also a simple application of the add_image_size function. To better highlight the use of special images, WordPress has been available since version 2.9.0.

Set_post_thumbnail_size function usage
This function is similar to the add_image_size function, except that it only sets the special image.

set_post_thumbnail_size( $width, $height, $crop)

Parameter details

  • $ Width: Image width
  • $ Height image height
  • $ Crop: whether to crop the image based on the height and width

Instance

set_post_thumbnail_size(100,0,true);

Note: when either the height or width is 0, WP automatically adapts to the other value for generating thumbnails.

Function declaration

/** * Registers an 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.