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.

Here's my code:

    function widget($args, $options) {
    extract($args);

    global $post;
    $post_type = $options['post_type'];
    $num_of_posts = $options['limit'];

    // Create a new instance
    $second_query = new WP_Query( array(
                        'post_type' => "$post_type",
                        'posts_per_page' => "$num_of_posts",
                        'post_status' => 'publish',
                    ) ); 

    // The Loop
    if ($second_query->have_posts()) :
      while( $second_query->have_posts() ) : $second_query->the_post();
          $content .= '<span><a href="' .get_permalink(). '">' . get_the_title($post->ID) . '</a></span>';
          $content .= '<div>' .get_the_post_thumbnail($post->ID, array(290,290)). '</div>';
          $content .= '<p>' . get_the_excerpt() . '</p>';
      endwhile; else :
          $content = '<p>No ' . $options['post_type'] . 's found.</p>';
    endif;
    wp_reset_postdata();

    $title = "<h3>" . $options['title'] . "</h3>";

    echo $before_widget.$title.$content.$after_widget;
}

Everything displays fine except the thumbnail :-\

share|improve this question
    
Add global $post before the code. –  kaiser Jul 26 '11 at 17:07
    
kaiser: it's already part of the code... –  Joann Jul 26 '11 at 23:23
    
Nice. But I can't see it anywhere. Guessing what code could be there is the opposite of funny... How about posting your whole code. –  kaiser Jul 26 '11 at 23:29
    
@kaiser: I'have updated my post.. pasted the whole function.. –  Joann Jul 27 '11 at 0:04
    
BTW, thumbnail support is already enabled in functions.php –  Joann Jul 27 '11 at 0:16

1 Answer 1

up vote 4 down vote accepted

Try just get_the_post_thumbnail(). Leave the $post->ID out of it.

Edit: Never mind, get_the_post_thumbnail does require the ID. I'd use the get_the_ID() function instead of $post->ID, but that shouldn't matter.

share|improve this answer
    
didn't work. Even tried echo'ing it. –  Joann Jul 26 '11 at 23:23
    
Dumb question: Does the post in question even have a thumbnail? –  Otto Jul 27 '11 at 0:49
    
Dumb question too: I placed an image into the post in the editor panel, will wp use that as the thumbnail? Or I have to do something custom to add a thumbnail to the post? :-\ –  Joann Jul 27 '11 at 1:14
    
Images placed in the editor aren't counted as post thumbnails, there's a seperate metabox(typically on the righthand side of the editor screen) for adding a featured/thumbnail image to the post. If you don't see that metabox check under screen options. –  t31os Jul 27 '11 at 8:22
    
Yes, an image in the post isn't the thumbnail. There's a special metabox on the Edit Post page called Featured Image where you can select an image for the thumbnail. Check the Screen options if you don't see it. –  Otto Jul 27 '11 at 18:32

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.