最简单、最直接的方法是:
$tax_terms = get_the_terms(
$post->ID,
array(\'genre\')
);
$tax_terms = wp_list_pluck($tax_terms,\'slug\');
post_class(implode(\' \',$tax_terms));
您还可以将筛选器应用于
post_class
这基本上是一样的。
function tax_classes_wpse_105386($classes) {
global $post;
$tax_terms = get_the_terms(
$post->ID,
array(\'genre\')
);
$tax_terms = wp_list_pluck($tax_terms,\'slug\');
$classes = array_merge($classes,$tax_terms);
return $classes;
}
add_filter(\'post_class\',\'tax_classes_wpse_105386\');
但我确信您需要更复杂的逻辑——例如,可能仅限于某些post类型。