Display thumbnail from custom field

can you explain why do you need custom fields ? (personally i think they are HUGELY over-used.. especially for images )

if there is no specific reason why you need it , you could use the the_post_thumbnail(); function .

like so :

the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)

all you have to do , is when you upload your image – define it as “featured image”

(first check if your functions.php file has this line: add_theme_support('post-thumbnails'); and if not – then add it .

if you want to go further and add some more custom sizes , you can add also this :

set_post_thumbnail_size( 150, 230, true ); // Normal default post thumbnails
add_image_size( 'single-post-thumbnail', 400, 9999 ); // Permalink thumbnail size
add_image_size( 'example_name_2', 100, 100, false ); // example_name_2 thumbnail size
add_image_size( 'example_name_3', 50, 50, true ); // example_name_3  thumbnail size

etc.. et..
you can add as many as you like, and then call them like :


(newbie note – all the above code should be placed in functions.php file.
the function call the_post_thumbnail(); is to be places inside the loop.)

Leave a Comment