• Resolved Lindsey

    (@lalindsey)


    I’m trying to display a thumbnail next to the post excerpt using query_posts, but the_post_thumbnail() function isn’t working. I don’t know if it is a conflict with the query_posts function or not, but any help would be appreciated.

    Here is a sample of the code:

    <?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;?>

    Also, yes I have added the post-thumbnails add_theme_support code to the functions.php file as well:

    <?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
    ?>
Viewing 13 replies - 1 through 13 (of 13 total)
  • have you added the posts after the code was added, WordPress does not retrospectivly update the thumbnails?

    Test one by setting the ‘feature image’, Posts > Posts > edit and assign the featured image.

    HTH

    David

    Thread Starter Lindsey

    (@lalindsey)

    Yeh, I just tried it again adding a new post, new image, still a no go ??

    I cannot see anything wrong so it would be a case of elimination.

    It might be something to do with the span class so start by moving the image output, and testing to see if any appear!

    <div class="theme">
    <div class="cms-image" style="float: left; margin: 5px 5px 0 0;">
    	<?php the_post_thumbnail(); ?>
    </div>
    <div class="cms-image" style="float: left; margin: 5px 5px 0 0;">
    	<?php the_post_thumbnail('article-post-thumbnail'); ?>
    </div>
    <div class="cms-image" style="float: left; margin: 5px 5px 0 0;">
    	<?php the_post_thumbnail('mini-post-thumbnail'); ?>
    </div>

    Then if you get images add the link and re-structure the style element, check your style in the style.css etc:

    HTH

    David

    Thread Starter Lindsey

    (@lalindsey)

    It’s so weird. I tried to remove all the clutter around it. But within the query_posts it won’t show at all. When I view the source there isn’t even anything in there like the image link or anything. It’s just blank. :/

    I think I’m just going to have to default back to custom field until I can solve this one! Very frustrating.

    Thanks,
    Lindsey

    The same thing is happening to me with the most recent WP version … looks like a bug.

    Don’t use add_theme_support('post-thumbnails') in themes. It’s only meant to be used internally by WP.

    Thread Starter Lindsey

    (@lalindsey)

    I’m only following the instruction as provided by the codex and the link provided to an outside resource in the codex.

    It says to use add_theme_support that into the functions.php file in both the codex and on the external site.

    From the codex:

    To enable post thumbnails, the current theme must include add_theme_support( ‘post-thumbnails’ ); in its functions.php file. See also Post Thumbnails.

    Anyway, I ditched that method for now, and I’m just using the custom post values to generate my thumbnails for now.

    -Lindsey

    Wait! Although that method is certainly ditchable (and probably should be reported), get_posts() still works, and

    <?php
     $lastposts = get_posts('numberposts=3');
     foreach($lastposts as $post) :
        setup_postdata($post);
     ?>
    		<?php the_post_thumbnail(); ?>
     <?php the_content(); ?>
     <?php endforeach; ?>

    works perfectly.

    Not a perfect solution, but works for my project…

    – n.

    Thread Starter Lindsey

    (@lalindsey)

    Hey nlaffan –
    I am definitely going to check that out – it would be a perfect solution for me to get the thumbnails working since using the custom values means entering another row of data AND cropping and upload a thumbnail. This will save me a lot of time. I’m going to try this first thing in the morning!

    Thanks,
    Lindsey

    inovawebdesign

    (@inovawebdesign)

    In case this helps anyone, I was facing a similar issue: the_post_thumbnail() just wouldn’t display the thumbnail. I can’t totally explain the “why,” but I the reason it didn’t work is because I was calling the_post_thumbnail() AFTER get_sidebar(). In order to work around it, the simple solution was echo get_the_post_thumbnail( $post->ID, $size, $attr )

    Thread Starter Lindsey

    (@lalindsey)

    Boo! So, working on another project and ran into this issue yet again, although this time instead of just not showing the thumbnail it completely stops fetching all data for the rest of the page… I remove the <?php the_post_thumbnail(); ?> and all works fine…

    Anyone?

    Two thoughts:

    1) Are you duplicating any PHP open or close tags? <?php or ?>

    2) Maybe try <?php echo get_the_post_thumbnail(); ?> just in case it’s something about the way the_post_thumbnail() prints its content?

    Thread Starter Lindsey

    (@lalindsey)

    Hey guys,

    I got this to work! I’m not sure what the change was, but using both query_posts and get_posts this is working ok for me now!

    Good luck to everyone else!

    -Lindsey

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Using query_posts the_post_thumbnail doesn't seem to work’ is closed to new replies.