If you want to show featured image of latest post for each unique posts published in WordPress? Also to demonstrate the point, you made no attempt to actually check the posts.
Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | if ( $query->have_posts() ) { while($query->have_posts()) { $query->the_post(); ?><h2><?php the_title(); ?></h2> <?php // you only need open/close tags here, not every line, save yourself some time typing if ( has_post_thumbnail() ) { //only print out the thumbnail if it actually has one echo '<p>post says it has a featured image</p>'; // double checking the_post_thumbnail('thumbnail'); } else { echo '<p>this post does not have a featured image</p>'; } } } else { echo '<p>no posts found</p>'; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.