WordPress: Showing an image in the excerpt – using either the_post_thumbnail( ); or Get The Image plugin

Question:

I prefer showing only post excerpts on the home page, but I would like a thumbnail image attached to each excerpt. How to achieve this?

Answer:

Two solutions:

1. Use the new the_post_thumbnail function in WordPress 2.9

Tutorial:

http://www.kremalicious.com/2009/12/wordpress-post-thumbnails/

http://poplicola.com/using-the_post_thumbnail-with-wordpress-2-9/

http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature

2. Use Justin Tadlock’s Get The Image plugin.

Tutorial:

http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin

==============================

Important notes for the_post_thumbnail:

1. To enable the_post_thumbnail for your theme:

Add the following to the functions.php file in your theme

add_theme_support(‘post-thumbnails’);

For backwards compatibility you should wrap this inside a function check for the new add_theme_support:

if ( function_exists( ‘add_theme_support’ ) )
add_theme_support( ‘post-thumbnails’ );

This makes sure WordPress installation prior to 2.9 won’t get screwed up when using a theme with this new feature.

2. Add a Post Thumbnail to your post:

After you’ve added the above mentioned code into your functions.php file there should be a new Post Thumbnail box in the WordPress editor view on the right side.

In this box click on the Set Thumbnail link and the usual Add Media dialogue will pop up where you can choose an image from your Media Library. At the end of the dialogue for the selected image there’s a new link beside the Insert into Post button called Use as thumbnail.

Click this and your chosen image will be assigned as the post thumbnail.

(Important note: Unfortunately the Use as thumbnail link is missing in the dialogue which appears after uploading an image, it’s just there if you browse your Media Library.)

You can close the media dialogue now and you will see the image in the Post Thumbnail box.

3. Display the post thumbnail in your theme:

Add the line below to your theme’s index.php

<?php the_post_thumbnail(); ?>

Or for various sizes of the thumbnail:

<?php the_post_thumbnail(‘thumbnail’); ?>

<?php the_post_thumbnail(‘medium’); ?>

<?php the_post_thumbnail(‘large’); ?>

Credits: Matthias

More info, read at: http://www.kremalicious.com/2009/12/wordpress-post-thumbnails/

==========================================

Important notes for Get The Image plugin:

1. This plugin was made to easily find images and add them on pages where the full post isn’t shown. This is the order in which the plugin attempts to grab an image.

  • Looks for an image by custom field.
  • If no image is added by custom field, check for a post thumbnail (WordPresss 2.9+ feature, see above).
  • If no image is found, it grabs an image attached to your post.
  • If no image is attached, it can extract an image from your post content (off by default).
  • If no image is found at this point, it will default to an image you set (not set by default).

2. To add an image by custom field, create a Key named “thumbnail.” Give it a Value of the URL of the image you uploaded (ex: /wp-content/uploads/image.gif). That’s it!

More info on Add an image by custom field, read: http://justintadlock.com/archives/2007/10/27/wordpress-custom-fields-adding-images-to-posts

3. Get The Image plugin will not recognize images embeded by NextGen Gallery!

Question by cubus (January 7, 2009 at 8:59 am)

Hello Justin,

I wanted to use this plugin on one of my client’s site. The problem is that all images that are used in the posts are embedded via the Nextgen Gallery plugin. I used it to that plugin to centralize all the images / slideshow. In the latest versions of the plugin you can just pick a picture from you slideshows to embed in your post just like you would doing with the default wordpress gallery.

Now, unfortunately your plugin doesn’t recognize the images ‘attached’ to a post via de Nextgen gallery. I don’t know exactly how your plugin finds the image in the blogpost but I saw in the source code that Nextgen embeds the images on a different way then the wordpress gallery (it uses a shortcode [singlepic])

Answer by Justin Tadlock (January 24, 2009 at 6:08 am)

Cubus — This plugin uses attachment images by WordPress standards. It’s not my plugin that should be working with NextGen. NextGen should work within the confines of WordPress.

Source: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin

=====================================

Advertisements
%d bloggers like this: