get_the_post_thumbnail() not working in a page template

The following code is placed inside an include file named latest-web.php :

                    $args = array( 'numberposts' => '8', 'category_name' => 'web-reference' );
                    $recent_posts = wp_get_recent_posts( $args );
                    foreach( $recent_posts as $recent ){
                        $featured_image = get_the_post_thumbnail();
                        $poveznica = get_field('link-projekta');
                        echo '<figure class="effect-winston">
                        ' . $featured_image . '
                            <h2><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a></h2>
                                <a href="' . get_permalink($recent["ID"]) . '"><i class="fa fa-fw fa-list"></i></a>
                                <a href="' . $poveznica . '" target="_blank"><i class="fa fa-fw fa-link"></i></a>

When including the file in index.html, it works flawlessly, but when including it in the page template, there is a problem. The code pulls all the info correctly. However, the image/thumbnail is not displayed at all. There is no img tag when inspecting from the browser. Does anyone have a solution for this?


Read more here: get_the_post_thumbnail() not working in a page template

Leave a Reply

Your email address will not be published. Required fields are marked *