2013-05-24 3 views
0

미리보기 이미지가없는 모든 게시물을 건너 뛰고 싶습니다. 코드가 아직 제대로 작동하지 않습니다.WordPress Loop - 미리보기 이미지가없는 게시물 건너 뛰기

실제로 스크립트는 미리보기 이미지가없는 게시물을 표시하지 않습니다. 좋습니다.하지만 루프에서 미리보기 이미지가없는 게시물은 여전히 ​​게시물로 계산됩니다.

예를 들어 내 워드 프레스 데이터베이스에 10 개의 게시물이있을 때. 나는 그들 중 5 명을 보여주고 싶다. 그러나 미리보기 이미지가있는 게시물 만 빈 문자열을 검사하는 것은 완벽하게 당신

$args = array( 'numberposts' => 5, 
       'orderby'  => 'date', 
       'order'  => 'DESC', 
       'post_type' => 'post', 
       'post_status' => 'publish' , 
       'meta_query' => array(
        array(
         'key' => '_thumbnail_id', 
         'compare' => '!=', 
         'value' => null 
        ) 
       ) 
      ); 

답변

1

$args = array( 'numberposts' => 5, 
       'orderby'  => 'date', 
       'order'  => 'DESC', 
       'post_type' => 'post', 
       'post_status' => 'publish' , 
       'meta_query' => array(
        array(
         'key' => '_thumbnail_id', 
         'compare' => '!=', 
         'value' => '' 
        ) 
       ) 
      ); 

하거나보십시오. 고맙습니다.

+1

작품 작동하지 않은 경우

<ul> <?php $args = array( 'numberposts' => 5, 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish' ); $my_posts = get_posts($args); global $post; foreach($my_posts as $post) : setup_postdata($post); if (!has_post_thumbnail()) { continue; } else { ?> <li> <div class="clearfix" > <div class="thumb"><?php the_post_thumbnail('post-image-big'); ?></div> <a href="<?php the_permalink(); ?>" class="title"><?php the_title(); ?></a> <p class="category"><?php the_category(', '); ?></p> </div> </li> <?php } ?> <?php endforeach; ?> </ul> 
sascha