has_category()
会成功的。您可以向它传递一个ID或slug,或一组ID或slug,它将返回true
如果该职位有任何给定类别:
// ID
if ( has_category( 1 ) ) {
the_post_thumbnail( \'full\', array( \'class\' => \'img-responsive\' ) );
}
// Slug
if ( has_category( \'one\' ) ) {
the_post_thumbnail( \'full\', array( \'class\' => \'img-responsive\' ) );
}
// IDs
if ( has_category( [1, 2, 3] ) ) {
the_post_thumbnail( \'full\', array( \'class\' => \'img-responsive\' ) );
}
// Slugs
if ( has_category( [\'one\', \'two\', \'three\'] ) ) {
the_post_thumbnail( \'full\', array( \'class\' => \'img-responsive\' ) );
}
您可以通过添加
!
对于条件,指示“不是”:
if ( ! has_category( [1, 2, 3] ) ) {
the_post_thumbnail( \'full\', array( \'class\' => \'img-responsive\' ) );
}