• Resolved Matt

    (@nib101)


    Hi guys, I am new to creating a theme and wonder if anyone can help?

    I am trying to display all the featured images from posts under a specific category (id=5) my index page and it’s not working using the following code:

    <?php 
    
    			$myblogPosts = new WP_Query('cat=5'); // Cat 5 is the blog category.
    
    			if ($myblogPosts->have_posts()) :
    
    				while ($myblogPosts->have_posts()) : $myblogPosts->the_post();
    			?>
    
    				<div class="hero_img"><?php the_post_thumbnail(); ?></div> <!--Post image-->
    
    			<?php endwhile; 
    
    			else : ?>
    				<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    			<?php endif; ?>

    Can anyone see why it’s not working? All I get is the “Sorry, no posts” displayed where the image should be.

    Thanks in advance!!

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Featured Image not showing on page’ is closed to new replies.