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) on 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.
BTW, I got the cat id from this URL (http://localhost:8888/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=5&post_type=blog)
Thanks in advance!!