我只想显示自定义post类型自定义分类法中的第一个术语。
在我的循环中,我一直使用以下方式显示所有术语:
<?php echo get_the_term_list( $post->ID, \'traits\', \'Physical Traits:\', \'\'); ?>
但我只想显示第一个术语。谢谢
我只想显示自定义post类型自定义分类法中的第一个术语。
在我的循环中,我一直使用以下方式显示所有术语:
<?php echo get_the_term_list( $post->ID, \'traits\', \'Physical Traits:\', \'\'); ?>
但我只想显示第一个术语。谢谢
有点复杂,但:
<?php
function get_single_term($post_id, $taxonomy)
{
$terms = wp_get_object_terms($post_id, $taxonomy);
if(!is_wp_error($terms))
{
return \'<a href="\'.get_term_link($terms[0]->slug, $taxonomy).\'">\'.$terms[0]->name.\'</a>\';
}
}
//example
echo get_single_term(5, \'category\');