您可能已经了解了这一点,但下面是一个示例,说明如何为帖子获取自定义分类术语,并为找到的术语创建链接列表。
// used in your custom post type template, e.g. single-movies.php
$genres = get_the_terms( get_the_ID(), \'genres\' );
// current post has genre terms attached to it
if ( $genres && ! is_wp_error( $genres ) ) {
$term_links = array();
// build list item links
foreach ($genres as $genre) {
$genre_links[] = sprintf(
\'<li><a href="%s">%s</a></li>\',
esc_url(get_term_link($genre->term_id, $genre->taxonomy)),
esc_html($genre->name)
);
}
// display genres link list
printf(
\'<ul>%s</ul>\',
implode(\'\', $genre_links)
);
}