下面的代码放在一个包含文件中名为最新-web.php:get_the_post_thumbnail()在页面模板不工作
<?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标签。有没有人有这个解决方案?
谢谢!
你试过 $ featured_image = get_the_post_thumbnail($ recent [“ID”]); – Ashkar
你好,我刚刚尝试过。在使用您的代码时,它在索引和页面模板上都不起作用。 – Rockbell