Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

* edit * - Pretty new to wordpress here and I've been working on getting post-thumbnails working using featured images...My goal is to quickly apply the featured image as a post thumbnail, regardless of which theme I am using....I've been editing the Twenty Eleven theme and it seems that the featured images only applies to the main header image, or at least any post I have added a featured image to, the image doesn't show up as a thumbnail. I did a little research and I have found some people saying that featured images in Twenty Eleven only update the main header image...I have tried a couple of plugins that didn't work with a couple of different themes.

Because I am new to WP and haven't really learned which features can easily be implemented via plugins and which require PHP editing, I have a couple of questions:

Am I right to think that featured images work differently depending on which theme you have installed?

Am I over looking something real easy, like a popular plugin that solves this issue?

Any help would be greatly appreciated. - * end edit *

share|improve this question

2 Answers 2

up vote 1 down vote accepted

As mentioned by @Michael in his answer the theme has to support the Post Thumbnail functionality. All you need to do for it is to put this line into the theme's function.php file:

add_theme_support( 'post-thumbnails' );

There's a good chance it's there already, so search first.

Now you only need to output the image somehow. There is a function called the_post_thumbnail(). You can copy and paste the following line almost anywhere in your theme files. Try index.php or single.php and you will see.

<?php the_post_thumbnail( 'thumbnail' ); ?>

These 1 or 2 steps are all that is needed for the very basic Post Thumbnail functionality. You can implement this into any theme.

You will find all this and much more (much better written also) in Everything you need to know about WordPress 2.9′s post image feature by Justin Tadlock. It's an excellent article I kept returning to the most when I was learning how to work with the featured images.

Good luck (again;) and let us know how it went and/or if you have more questions!

share|improve this answer
    
PS. back it up somehow and don't be afraid of editing the theme files. Child themes are a great way how to do this. –  Michal Mau Aug 28 '11 at 22:16
    
see also How to handle thumbnails –  Michal Mau Aug 28 '11 at 23:39

I must admit to similar complaints in figuring out how to use Featured Images in my Thesis theme. Eventually, I figured it out and have gotten positive comments about my use of images liberally at http://peimic.com.

I hope the code from my custom_functions.php file can help get you going.

Notes:

  • add_theme_support is needed to enable Featured Images in your Post edit screen.
  • set_post_thumbnail_size is the default image size to use when get_the_post_thumbnail or a variant of it is called without a size parameter.
  • add_image_size gives you the ability to define sizes other than the typical WordPress small, medium, etc.
  • add_action is the Thesis hook being used to inject the desired featured image into my post content whether it's the single page, home or other. If you don't have hooks or filters in your theme, then call post_thumbnail directly.
  • If you want to include featured images in your RSS feeds, then the prepend_content_thumbnail code will help you do just that.

    add_theme_support( 'post-thumbnails' );
    // set to my 'large'
    set_post_thumbnail_size( 590, 472, true );
    // teaser is currently same size as medium, but leaving adding option in
    add_image_size( 'teaser', 290, 232, true );
    
    
    function post_thumbnail() {
        if ( ! has_post_thumbnail( get_the_ID() ) )
            return;
    
        if ( is_single() ) {
            echo '<div class="post_thumbnail">';
            echo wp_get_attachment_link( get_post_thumbnail_id(), 'large', true );
            echo '</div>';
        } else {
            // achives, category, tags, etc. listings
            echo '<div class="post_thumbnail">';
            echo '<a title="';
            echo get_the_title();
            echo '" href="';
            echo get_permalink();
            echo '">';
            echo get_the_post_thumbnail( get_the_ID(), 'large' );
            echo '</a>';
            echo '</div>';
        }
    }
    
    add_action('thesis_hook_before_post','post_thumbnail');
    
    
    function teaser_thumbnail() {
        if ( ! has_post_thumbnail( get_the_ID() ) )
            return;
    
        echo '<div class="teaser_thumbnail">';
        echo '<a title="';
        echo get_the_title();
        echo '" href="';
        echo get_permalink();
        echo '">';
        echo get_the_post_thumbnail( get_the_ID(), 'teaser' );
        echo '</a>';
        echo '</div>';
    }
    
    add_action('thesis_hook_before_teaser_headline','teaser_thumbnail');
    
    
    function prepend_content_thumbnail( $content ) {
        if ( ! has_post_thumbnail( get_the_ID() ) )
            return $content;
    
        $thumb                      = '<div>';
        $thumb                      .= '<a title="';
        $thumb                      .= get_the_title();
        $thumb                      .= '" href="';
        $thumb                      .= get_permalink();
        $thumb                      .= '">';
        $thumb                      .= get_the_post_thumbnail( get_the_ID(), 'large' );
        $thumb                      .= '</a>';
        $thumb                      .= '</div>';
    
        return $thumb . $content;
    }
    
    add_filter( 'the_excerpt_rss', 'prepend_content_thumbnail' );
    add_filter( 'the_content_feed', 'prepend_content_thumbnail' );
    
share|improve this answer
    
thanks for taking the time out, I appreciate it, and I'll look into what you provided –  kdub Aug 28 '11 at 15:23
2  
All those thesis hooks will only work with... thesis. Furthermore: An echo statement in every row is a) hard to read and b) not necessary. You can just open your double quotes, write on multiple lines and close them later again. Every var will be used - only functions won't work. –  kaiser Aug 28 '11 at 23:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.