当使用“orderby = comment_count”后,缩略图消失(WordPress)
问题描述:
我试图根据我的边栏中的评论显示最受欢迎的帖子。我想让帖子缩略图显示在标题旁边,但是当我使用'orderby = comment_count'对我的帖子进行排序时,缩略图消失。如果我根据类别名称显示帖子,则会显示缩略图。作为参考,这里是我的代码:当使用“orderby = comment_count”后,缩略图消失(WordPress)
<?php $post_by_comment = new WP_Query('orderby=comment_count&posts_per_page=6'); ?>
<?php while ($post_by_comment->have_posts()) : $post_by_comment->the_post(); ?>
<?php if (has_post_thumbnail()) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
<?php endwhile;?>
如果我使用完全相同的代码,但变化:
<?php $post_by_comment = new WP_Query('orderby=comment_count&posts_per_page=6'); ?>
到
<?php $post_by_comment = new WP_Query('category_name=categoryname&posts_per_page=6'); ?>
后缩略图显示刚精细。我在这里做错了什么?
答
尝试get_the_post_thumbnail并将其传递给您要查找的ID。
get_the_post_thumbnail($post_by_comment->ID, 'thumbnail');
我想,为什么这是怎么了?也许是the_post_thumbnail预计ID为$后> ID而不是$ post_by_comment-> ID(你有)。
我也会使用get_posts而不是开始一个新的查询,如果这只是一个侧面列表,而不是页面的主要内容。
哦,别忘了回应get_the_post_thumbnail! – addedlovely 2011-06-11 14:02:57