• I am attempting to get a list of featured posts (based on a category) with thumbnail into a sidebar using the following function.

    It works great, but unfortunately pulls in the SAME thumbnail for every post. Whatever happens to be the most recent item put into that category is the thumbnail that shows up for ALL the posts.

    Any ideas on what’s causing this?

    function featured_posts_sidebar() {
    
      ?>
    
    <div id="images_box_thumbs">
    <div class="sidebar_title">Featured Posts</div>
    			<?php $query = new WP_Query('category_name=featured&showposts=6'); ?>
    <?php while ($query->have_posts()) : $query->the_post(); ?>
    
    <div id="images_box"><!-- Category Image Posts -->
    
     					<a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">			<a href="<?php the_permalink() ?>" rel="bookmark"> <?php
    $files = get_children("post_parent=$id&post_type=attachment&post_mime_type=image");
    if($files){
            $keys = array_keys($files);
            $num=$keys[0];
    		$thumb=wp_get_attachment_thumb_url($num);
    
            print "<div class='photo_thumb'><a href='".get_permalink()."' title=''><img src='$thumb' class='thumbnail' alt='' /></a></div>";
    }
    ?></a><br />
    <a class="gal_link" title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
    <a class="gal_read_more" title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">Read More >></a>
    
    </div>
    
    <?php endwhile; ?>
    
    <div style="clear:both;"></div>
    
    <h3><a href="https://mysite.com/category/gallery/">More Photo Galleries &raquo;</a></h3>
    
    </div><!-- Recent Galleries Ends -->
    <?php
    		}
  • The topic ‘Featured Posts with Thumbnail’ is closed to new replies.