wordpresswordpress-themingcustom-wordpress-pages

How to display every featured image of a post in a post in wordpress


I have a single page template called single-businesses.php which shows different brands and its information. However underneath, I want to show featured images of every post within this file. Is there any way to do this in wordPress?


Solution

  • Yes, you can use a loop to do that. Similar to how posts are displayed in your blog page. Just exclude the_content() and anything else you don't need. The following code will display only the featured images (which are referred to as the_post_thumbnail()):

    <?php 
    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post(); 
            the_post_thumbnail();
        }  //end while
    } //end if
    ?>