Having trouble with the_post_thumbnail to display thumbnail with custom size

I have code that looks like this:

$post_thumbnail = the_post_thumbnail( array ( $w, $h ) );

I want to know what I’m doing wrong. When I pass in values for width and height, WordPress returns an image with the correct hight but with the incorrect width. Is it possible for me to get the exact image specified?

Related posts

Leave a Reply

1 comment

  1. Always start with the Codex. According to the function reference for the_post_thumbnail():

    Parameters

    $size

    (string/array) (Optional) Image size. Either a string keyword (thumbnail, medium, large, full), or any custom size keyword defined by add_image_size(), or a 2-item array representing width and height in pixels, e.g. array(32,32).

    Default: ‘post-thumbnail’, which theme sets using set_post_thumbnail_size.

    PLEASE NOTE: The crop does not work in Wp 3.0+. All that is needed for WP 3.0+ is the call for the thumbnail to post. Then proceed to media in the dashboard and set your thumbnail to crop to the size you wish to use.

    You need to create your custom image size, via add_image_size( $name, $w, $h, $crop ), and then call the_post_thumbnail( $name ).