The thumbnail is an image that is chosen as the representative image for Posts, Pages or Custom Post Types. The display of the thumbnail is up to the theme and whether it has been enabled. Thumbnail images are especially useful for “magazine-style” websites where each post has an image.
To enable thumbnails or “Featured Image”, just add the following code to your functions.php file:
if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); }
Now to display the thumbnail within your theme, you simply just add the following code where you want the image to show: the_post_thumbnail();
. The only problem with this is that the default “alt” and “title” tags are the filename of the actual image, and not the post. This is easily fixed as WordPress allows you to change the parameters to whatever you want, just change to the following:
the_post_thumbnail( 'thumbnail', array('alt' => ''.get_the_title().'', 'title' => ''.get_the_title().'' ));
You can also add/change other attributes like this:
the_post_thumbnail( 'thumbnail', array('class' => 'alignleft post_thumbnail', 'style' => 'width: 150px;', 'alt' => 'no alt', 'title' => ''.get_the_title().'' ));