How to fill “gray thumbnail box” with thumbnail image?

Posted: June 14, 2010 in PHP
Tags: , ,

Go to “custom fields” section and add a new field as thumbnail and put the image path in the value field. See the example

Now put the following code in the custom theme’s template file

<?php
if(get_post_meta($post->ID, 'thumbnail', $single = true)) :
echo '<img src="'.get_post_meta($post->ID, 'thumbnail', $single = true).'" title="'.$post->post_title.'" width="98" height="82" />';
endif;
?>
About these ads
Comments
  1. Paul says:

    Hi,

    Your instructions are to “put the following code in the custom theme’s template file” I don’t know very much about php but am comfortably opening up the file and pasting. I’m using WP Weaver, a sub-them of 2010 Weaver. I am guessing I should paste the above code in “single.php”, which is a template for displaying all single posts. Do you know if I am on the right track? There are many div tags within this file. At what point do I paste the above text? Thanks for any help you can give.

    Paul

    • chinmoy29 says:

      Hi,

      You already used the latest version of wordpress. There have a feature for thumbnail. Use that once. If you enable the “post-thumbnail” feature from funtions.php file then this feature will view at left panel on ADMIN->ADD/EDIT POST section.

      Single.php file shows the whole details of a post. Why you put the thumbnail in this page? I think that There will see the big image. Thumbnail will be came in index.php file.

      Chinmoy

      • Paul says:

        Thanks for your response. I did end up solving my problem. Yes, you are right, my current version of WordPress and my theme (Twenty Ten) do support thumbnails, but in a weird sort of way.

        When writing a post I can upload a thumbnail image to the “featured image” box. I didn’t find a way to edit the php to allow this image to show, so I found a great plugin that does this very thing called “Thumbnail For Excerpts”. The plugin will either use the featured image thumbnail I have uploaded, or, if one does not exist, then it will use the first image embedded in a post as a thumbnail source These thumbnails show when when clicking on categories, searching through archives, etc).

        I looked in functions.php and 2010functions.php all within my wp-content/themes/2010-weaver directory and found some interesting code:

        Within the function twentyten_setup() I found the following command:
        add_theme_support( ‘post-thumbnails’ );

        So the thumbnail feature does seem enabled. But even after I’ve uploaded thumbnail images to the “featured image” box within posts, the thumbnails don’t show unless I’ve activated the above-mentioned plugin.

        Oh well, I don’t know enough php or programming to figure out the details, but I got it to work all the same. Thanks for you help.

  2. fran says:

    OMG! Paul you are awesome! thank you so much for posting that…. i have been trying to do this for ages and couldn’t figure it out!

    Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s