我怎样才能获得这段代码来仅提取某些类别的缩略图?

时间:2013-12-05 17:55:57

标签: html wordpress thumbnails categories

我正在尝试使用此代码在我的Wordpress页面上仅提取“静止图像”类别。我尝试了一些不同的东西,但它只是拉出了所有类别的缩略图。

<?php
$args = array( 'numberposts' => '12' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
    if ( has_post_thumbnail($recent["ID"])) {
        echo '<li>' . get_the_post_thumbnail($recent["ID"], 'thumbnail') . '</li>';
    }
}?>

1 个答案:

答案 0 :(得分:0)

您可以尝试:

<?php
$args = array( 'numberposts' => '12' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
  if ( has_post_thumbnail() ) {
    if (is_category('stills')){
      the_post_thumbnail( 'thumbnail' );
    }
  }
}?>