<p> <?php $terms = wp_get_post_terms($post->ID, \'sublocation\');
if ($terms) {
foreach ($terms as $term) {
$out[] = \'<a class="\' .$term->slug .\'" href="\' .get_term_link( $term->slug, \'sublocation\') .\'">\' .$term->name .\'</a>\';
}
echo join( \', \', $out );
} ?>
</p>
<p>TYPE OF MUSIC: <?php $terms = get_the_terms($post->ID, \'music\');
if ($terms) { foreach ($terms as $term) {
$out[] = \'<a class="\' .$term->slug .\'" href="\' .get_term_link( $term->slug, \'music\') .\'">\' .$term->name .\'</a>\';
} echo join( \', \', $out );
}?>
</p>
<p>TYPE OF PUB: <?php $terms = wp_get_post_terms($post->ID, \'pub\');
if ( !empty( $terms ) ) {
foreach ($terms as $term) {
$out[] = \'<a class="\' .$term->slug .\'" href="\' .get_term_link( $term->slug, \'pub\') .\'">\' .$term->name .\'</a>\';
}
echo join( \' \', $out );
} ?>
</p>
打了这个电话后,我变得这样了
请参见上图,每种类型上的类别显示相同。
请问我怎样才能解决这个问题
最合适的回答,由SO网友:Faishal 整理而成
<p> <?php
$terms = wp_get_post_terms ( $post -> ID , \'sublocation\' ) ;
if ( $terms ) {
foreach ( $terms as $term ) {
$out[ ] = \'<a class="\' . $term -> slug . \'" href="\' . get_term_link ( $term -> slug , \'sublocation\' ) . \'">\' . $term -> name . \'</a>\' ;
}
echo join ( \', \' , $out ) ;
}
?>
</p>
<p>TYPE OF MUSIC: <?php
$terms = get_the_terms ( $post -> ID , \'music\' ) ;
if ( $terms ) {
$out = array ( ) ; // reInitialise
foreach ( $terms as $term ) {
$out[ ] = \'<a class="\' . $term -> slug . \'" href="\' . get_term_link ( $term -> slug , \'music\' ) . \'">\' . $term -> name . \'</a>\' ;
}
echo join ( \', \' , $out ) ;
}
?>
</p>
<p>TYPE OF PUB: <?php
$terms = wp_get_post_terms ( $post -> ID , \'pub\' ) ;
if ( ! empty ( $terms ) ) {
$out = array ( ) ; // reInitialise
foreach ( $terms as $term ) {
$out[ ] = \'<a class="\' . $term -> slug . \'" href="\' . get_term_link ( $term -> slug , \'pub\' ) . \'">\' . $term -> name . \'</a>\' ;
}
echo join ( \' \' , $out ) ;
}
?>
</p>