treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Using query_posts in Wordpress - the_post_thumbnail isn't working

  • Anyone successfully use the_post_thumbnail when using query_posts in Wordpress? I'm working on this right now, and I can't get the images to show at all.

    I've added the appropriate code to the functions.php file -
    <?php add_theme_support('post-thumbnails');
    set_post_thumbnail_size( 194, 155, true ); // Theme post thumbnails
    add_image_size( 'article-post-thumbnail', 281, 162 ); // Article thumbnail size
    add_image_size( 'mini-post-thumbnail', 80, 80 ); // Mini thumbs
    ?>


    And here is the code I'm using for my posts :

    <?php query_posts('showposts=2&cat=8'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="theme">
    <a href="<?php the_permalink(); ?>"><span class="thumb"><?php the_post_thumbnail(); ?></span></a>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <p class="author"><strong>Author:</strong> <a href="<?php the_permalink(); ?>"><?php $themeAuthor = get_post_custom_values('Author'); echo $themeAuthor[0]; ?></a></p>
    <?php the_excerpt(); ?>
    <p class="cats"><?php the_category(', '); ?></p>
    <p><a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_url'); ?>/images/download.gif" alt="Download <?php the_title(); ?> Now!" /></a></p>
    </div>
    <?php endwhile;?>


    Everything is working A-OK aside from the_post_thumbnail() :( Do I have to somehow modify the way I call it since I'm using query_posts?

    Any help would be super awesome!
    Thanks,
    Lindsey
  • Echo?
  • Try this for chuckles...

    <?php echo get_the_post_thumbnail(); ?>
  • Do you have a live example? I've used <?php the_post_thumbnail();?> quite a few times and I've never had a problem.
  • "showposts" is deprecated, try posts_per_page

    I don't know if this will have any effect, but give it a try!

    ie:

    change: <?php query_posts('showposts=2&cat=8'); ?>
    to: <?php query_posts('posts_per_page=2&cat=8'); ?>