[英]Get Wordpress posts so things like get_post_thumbnail_id don't make a database call
[英]wordpress — Get posts if they had a thumbnail
誰知道,我怎么能只得到帖子,什么有縮略圖? 我在 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 );
來檢查帖子是否有拇指has_post_thumbnail( $post_id );
例子 :
<?php
while ( have_posts() ) : the_post();
if(has_post_thumbnail( the_ID )) {
#code....
}
endwhile;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.