下面的代码放置在一个名为placed web.php的包含文件中:
<?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标记。有人有办法解决这个问题吗?
谢谢!
发布于 2017-05-15 10:27:38
请试试这个,在缩略图功能中添加了最近的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();
?>发布于 2017-05-16 10:12:48
在某些时候,get_the_post_thumbnail()不起作用,直到您传递post的ID,所以在您的例子中foeach循环中,您必须在get_the_post_thumbnail()中传递recentID,所以它看起来像get_the_post_thumbnail(最近的‘ID’),并且您完成了
https://stackoverflow.com/questions/43976350
复制相似问题