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.

I'm stumped. I've pored over all the articles here and beyond to no avail. I'm trying to simply display the post thumbnail in a template page, but it will not show up.

I have thumbnails enabled for the theme in functions.php: add_theme_support ('post-thumbnails');

I removed the sizing function set_post_thumbnail_size( 150, 150 ); from functions.php and added array(150,150) as an argument to get_the_post_thumbnail

I've set the Featured Image in a couple posts to test it out.

I tried echoing out get_the_post_thumbnail and using the_post_thumbnail template tag. I tried both get_posts (along with setup_postdata($post);) and new WP_query methods. No such luck.

I don't think it matters, but I'm using a child of the Twenty Eleven theme.

I have a template page set up and I'm calling a function I created in functions.php to list the posts. I'd like to use get_posts and echo it out like this: get_the_post_thumbnail( $post->ID, array(150,150) ). I've also tried inserting the function straight into the template page.

I've made every tweak I could think of. I don't see anything I'm overlooking, seems pretty straight forward. Any ideas? Any help would be greatly appreciated.

Here's the code I had initially before trying all the tweaks mentioned above.

In the functions.php file:

if ( function_exists( 'add_theme_support' ) ) { 
add_theme_support( 'post-thumbnails' ); 
}

set_post_thumbnail_size( 150, 150 );

And in my page template file:

function list_posts_by_cat_auth_year ($cat_text, $cat_id, $author, $year) {

echo '
<h1>'.$cat_text.'</h1>
<br />
<ol>';
global $post;

$args = array( 'posts_per_page' => -1, 'numberposts' => 0, 'category' => $cat_id, 'author' => $author, 'order' => 'desc' );

$myposts = get_posts( $args );
    foreach( $myposts as $post ) {
        $author = get_userdata($post->post_author);
        echo '
        <li>
        <div style="float:left">'
        .get_the_post_thumbnail( $post->ID, array(150,150) ).'
        </div>
        <a href="'.get_permalink().'">'.get_the_title().'</a>
        <br />
        <span class="post-summary">Posted on '.get_the_time('D, M jS, Y').' by '.$author->first_name.
        '<br />'.
        get_the_tag_list('Tagged:  ',' , ','').'
        </span>
        <br />
        ';

        echo '
        </li>
        <br />';
    };
echo '
</ol>
';
}
share|improve this question

1 Answer 1

Last I checked (meaning, it may have been updated in 3.5 and I just haven't noticed), passing an array for an arbitrary image size hasn't worked since before WordPress 3.0. You have to pass a pre-defined image size. Try:

  1. Define your custom image size:

    add_image_size( 'some-custom-name', 150, 150, true );
    

    (called along with add_theme_support( 'post-thumbnails' );)

  2. Then regenerate your thumbnails (e.g. via Plugin)

  3. Then pass your custom image size as the $size parameter:

    get_the_post_thumbnail( $post->ID, 'some-custom-name' )
    
share|improve this answer
    
Thanks for the response. I tried that and still no thumbnails. Any other ideas? –  Clinton Langosch Dec 11 '12 at 18:53
    
You're welcome. :) But did it work? –  Chip Bennett Dec 11 '12 at 18:55
    
Negative. Accidentally hit enter before. –  Clinton Langosch Dec 11 '12 at 18:57
    
What does var_dump( get_the_post_thumbnail( $post->ID, 'some-custom-name' ) ) return? –  Chip Bennett Dec 11 '12 at 18:58
    
it returns string(0) "" I'm assuming that means it's not finding a thumbnail. on the edit post screen I definitely have the Featured Image set. –  Clinton Langosch Dec 11 '12 at 19:14

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.