您可能需要先获取每个帖子类别的父类别。
<?php
$parent_cat = array();
$post_cats = get_the_category($post->ID);
foreach( $post_cats as $post_cat ) {
if( $post_cat->parent ) $parent_cat[] = get_category( $post_cat->parent )->slug;
}
?>
<article class="post <?php
if ( in_array( \'dream-it\', $parent_cat ) ) { echo \' dreamit\'; }
if ( in_array( \'build-it\', $parent_cat ) ) { echo \' buildit\'; }
if ( in_array( \'get-the-hell-out\', $parent_cat ) ) { echo \' getout\'; } ?> ">