Display post thumbnail in wordpress

By . Category: Wordpress Tags:

irnanto.comDisplay post thumbnail in wordpress is inseparable from the features that can be input images as thumbnails or often called a featured image in wordpress. Post thumbnail is an image that is used to identify or explain post or article made or thumbnail normally used for the depiction of an article. Post thumbnail display is usually done on themplate or wordpress themes that no post thumbnail setting its appearance. Therefore, this time I will give you a tutorial how to display post thumbnail in wordpress.

How to display the Post Thumbnails WordPress

I will give a little explanation of the source code to be used. The syntax to be used as follows:

<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>

Description :

  • $post_id : (Optional) id post. Default: post ID
  • $size : (Optional) contains a string that indicates the size (like thumbnail, medium, large, or full) or a representation of the width and height in pixel size, sample array(50,50). Default: ‘post-thumbnails’
  • $attr: (Optional) Query string or array of attributes (wp_get_attachment_image). Default: non $default_attr = array( ‘src’    => $src, ‘class’    => “attachment-$size”, ‘alt’    => trim(strip_tags( $attachment->post_excerpt )), ‘title’    => trim(strip_tags( $attachment->post_title )), );

Example Application Post Thumbnails

if((function_exists(‘has_post_thumbnail’)) && (has_post_thumbnail())) {
    echo get_the_post_thumbnail($post->ID,’thumbnail’);

Description :

  • function_exists(‘has_post_thumbnail’) is used to check whether or not the function has_post_thumbnail.
  • has_post_thumbnail() is used to check whether the return of has_post_thumbnail () true or false
  • echo get_the_post_thumbnail($post->ID,’thumbnail’); is used to display the results of the function get_the_post_thumbnail form of image tags.

Example Application Post Thumbnails with Parameter Size

get_the_post_thumbnail($post_id); // without parameters -> Thumbnail
get_the_post_thumbnail($post_id, ‘full’); // Original resolution
get_the_post_thumbnail($post_id, ‘large’); // Large resolution
get_the_post_thumbnail($post_id, ‘medium’); // Medium resolution
get_the_post_thumbnail($post_id, ‘thumbnail’); // Thumbnail
get_the_post_thumbnail($post_id, array(100,100) ); // Other resolutions

Ok, discussion on Display post thumbnail in wordpress, may be useful and can be applied properly. Aamiin


No comments yet untuk “Display post thumbnail in wordpress”

Tinggalkan Komentar