Display thumbnail from custom field

I have a custom field called picture. On the media settings page I’ve set thumbnail size to 100×100. If upload an image called gecko.jpg, WordPress automatically resizes it and generates gecko-100x100.jpg. I want to use both the thumbnail size and original size, is it possible?

With <?php echo get_post_meta($post->ID, 'picture', true); ?> I can only get the original size.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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)
the_post_thumbnail('full');

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 :

the_post_thumbnail('example_name_2');

(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.)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x