不同的输出,直到集合就绪。
$terms = get_the_terms( $post->ID, \'teams\' );
// create a collection with your default item
$classes = array(\'person\');
foreach ($terms as $term) {
// add items
$classes[] = $term->slug;
}
// output all the classes together with a space to separate them.
echo \'<div class="\' . implode(\' \', $classes) . \'">\';
echo \'<div>More markup for each person listing</div>\';
排除忽略添加任何项目:
if( $term->slug !== \'accounting\' ) { $classes[] = $term->slug; }
要清除所有坏苹果:
$pros = array(\'A\', \'B\', \'C\');
$cons = array(\'C\');
$best = array_diff($pros, $cons);
print_r ($best); // A, B
上下文:
$terms = get_the_terms( $post->ID, \'teams\' );
// create a collection with your default item
$classes = array( \'person\' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) {
$classes[] = $term->slug; // add items
}
}
// remove any specific classes here
$classes = array_diff( $classes, array( \'creative-services\' ) );
// output all the classes together with a space to separate them.
echo \'<div class="\' . implode( \' \', $classes ) . \'">\';
echo \'<div>More markup for each person listing</div>\';