我已经试着让帖子缩略图显示在foreach循环中好几个小时了,但我不知道如何让它工作,如果有任何帮助,我将不胜感激!
<div id="home-posts" class="col-sm-3" role="complementary">
<div class="recent-post-sidebar">
<h3>Popular Posts</h3>
<?php
$popular_post_object = new WDS_JetPack_Popular_Posts( array(
\'count\' => 5,
\'days\' => 200,
\'transient_affix\' => \'_mypp\')) ;?>
<?php $popular_post_results = $popular_post_object->get_posts();?>
<?php if ( !empty( $popular_post_results ) ) {
foreach( $popular_post_results as $popular_post ) {
echo \'<a href="\' . $popular_post[\'permalink\'] . \'">\';
echo \'<div class="post one">\';
echo \'<div class="post overlay"></div>\';
echo get_the_post_thumbnail($popular_post->ID, \'wpbs-featured-full\');
echo\'<h5>\'. $popular_post[\'title\'] .\'</h5>\';
echo \'</div>\';
echo \'</a>\';
}
}?>
</div>
</div>
代码的原始源代码是
WebDevStudios.
最合适的回答,由SO网友:Pieter Goosen 整理而成
如果阅读链接到的文档,您将看到post ID存储在数组键中post_id
而不是ID
.
然后你应该改变
get_the_post_thumbnail($popular_post->ID, \'wpbs-featured-full\');
至
get_the_post_thumbnail($popular_post[\'post_id\'], \'wpbs-featured-full\');