I wanted to show my recent 2 posts in main menu so I did few lines of code and achieved showing titles under the category name on hover, and also tried to fetch the first image of the post. The problem is, only the first-post in the list shows up its first-image, not other posts.
I am including the screen shot as it is on my localhost. -> ScreenShot
In the screenshot am hovering over “around Town” category to show two posts from it. In first post it is showing the first-image of the post; but not doing so in the second post. This is my question, why?
This is what I used Below-Header in simple hook ->
$featuredPosts = new WP_Query();
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>
<?php if ( get_the_post_thumbnail($post_id) !='' )
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<?php endwhile; ?>