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.

so, i wanted to thumbnails in my query and i came across add_theme_support, it says you have to have that to enable actions such as thumbnail, so i put the following in my functions

function pippin_add_thumbnail_support() {
    if(!current_theme_supports('post-thumbnails')) {
        add_theme_support('post-thumbnails');
    }
}
add_action('init', 'pippin_add_thumbnail_support');

Even after that code, my query doesn't generate a post thumbnail, when my query is

<?php
            $posts = get_posts(array('posts_per_page' => 4));
            foreach ($posts as $post) {
                if( has_post_thumbnail()){
                    get_the_post_thumbnail($post->ID,'thumbnail');

                echo $post->post_title;
                }

Am i missing something, or doing something wrong?

share|improve this question
1  
Have you put the 1st code in functions.php file? Also this may not directly work for the posts already added. You need to add/update the posts again to generate the required images or you can use regenerate thumbnails plugins to generate the images automatically. –  Chittaranjan Dec 14 '13 at 11:22
    
@Chittaranjan yes do have it in my functions.php , but i think it was add/update the posts, as you mention. it worked. –  Nofel Dec 14 '13 at 11:43
    
Since the above tip worked for you, I have added that as an answer below and you can accept that. –  Chittaranjan Dec 14 '13 at 14:41

2 Answers 2

up vote 0 down vote accepted

You need to echo the get_post_thumbnail in order for it to output.

echo get_the_post_thumbnail($post->ID,'thumbnail');
share|improve this answer

If you have images already added before adding the above piece of code, then you need to update the posts again to generate the required images. It will automatically work for all those posts which will be added from now.

If you have large number of images, then you can use Regenerate Thumbnails plugin to generate the images automatically.

share|improve this answer

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.