无法在Foreach循环中显示发布的缩略图

时间:2015-11-04 作者:Jamie Halvorson

我已经试着让帖子缩略图显示在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.

1 个回复
最合适的回答,由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\');

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请