我需要列出适用于这篇文章的分类法。如果分类法只有一个,那么这个代码工作得很好:
global $post;
$terms = wp_get_post_terms($post->ID, 'gintype');
if($terms){
$output = array();
foreach($terms as $term){
$outputnk[] = get_term_link( $term->slug, 'gintype');
$outputme[] = $term->name;
}
}
但是,如果一篇文章有几个分类项目,则此代码不起作用。
此代码适用于我:
global $post;
$terms = wp_get_post_terms($post->ID, 'gintype');
foreach($terms as $term){
$term_link = get_term_link( $term );
echo '<div><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>';
}