谁知道呢,我怎么能只得到帖子,什么有缩略图?我在WP文档中没有找到任何内容。请帮忙!get_posts() 的过滤器不包括缩略图。
这应该有效:
<?php
$loop = new WP_Query( array('meta_key' => '_thumbnail_id', 'post_type' => 'post'));
while($loop->have_posts()) : $loop->the_post();
?>
<h2><?php the_title(); ?></h2>
<?php the_post_thumbnail(); ?>
<?php endwhile; ?>
这将返回附加了缩略图(特色图像)的所有posts
。
你可以检查帖子有拇指或不使用has_post_thumbnail( $post_id );
例:
<?php
while ( have_posts() ) : the_post();
if(has_post_thumbnail( the_ID )) {
#code....
}
endwhile;
?>
函数引用/具有帖子缩略图