Wordpress 获取页面模板中不工作的\u post\u缩略图()

Wordpress 获取页面模板中不工作的\u post\u缩略图(),wordpress,loops,include,thumbnails,Wordpress,Loops,Include,Thumbnails,以下代码放在名为latest-web.php的include文件中: <?php $args = array( 'numberposts' => '8', 'category_name' => 'web-reference' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_po

以下代码放在名为latest-web.php的include文件中:

<?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 . '
                        <figcaption>
                            <h2><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a></h2>
                            <p>
                                <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>
                            </p>
                        </figcaption>           
                    </figure>';
                    }
                    wp_reset_query();
?>

在index.html中包含该文件时,它的工作方式是完美的,但在页面模板中包含该文件时,会出现问题。代码正确地提取所有信息。但是,根本不显示图像/缩略图。从浏览器进行检查时,没有img标记。有人能解决这个问题吗


谢谢

请尝试此操作,在缩略图功能中添加了最近的id

<?php
                    $args = array( 'numberposts' => '8');
                    $recent_posts = wp_get_recent_posts( $args );
                    foreach( $recent_posts as $recent ){
                        $featured_image = get_the_post_thumbnail($recent["ID"]);
                        $poveznica = get_field('link-projekta');
                        echo '<figure class="effect-winston">
                        ' . $featured_image . '
                        <figcaption>
                            <h2><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a></h2>
                            <p>
                                <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>
                            </p>
                        </figcaption>           
                    </figure>';
                    }
                    wp_reset_query();
?>

在某段时间内,在传递post的ID之前,get\u post\u缩略图()不起作用,因此在每个循环中,您必须在get\u post\u缩略图()中传递最近的[ID],
因此,它看起来像是获取帖子缩略图(最近的['ID']),而您已经完成了mate

您是否尝试过$featured\u image=get\u帖子缩略图($recent['ID');你好,我刚试过。当使用你的代码时,它在索引和页面模板上都不起作用。我一定是在第一次尝试时出错了。工作完美。非常感谢你!