您可以尝试以下操作:
/**
* List the taxonomies and terms for a given post
*
* @param int $post_id
* @return string
*/
function get_the_current_tax_terms_wpse( $post_id )
{
// get taxonomies for the current post type
$taxonomies = get_object_taxonomies( get_post_type( $post_id ) );
$html = "";
foreach ( (array) $taxonomies as $taxonomy)
{
// get the terms related to the post
$terms = get_the_terms( $post->ID, $taxonomy );
if ( !empty( $terms ) )
{
$li = \'\';
foreach ( $terms as $term )
$li .= sprintf( \'<li><a href="%s">%s</a></li>\',
get_term_link( $term->slug, $taxonomy ),
$term->name );
if( ! empty ( $li ) )
$html .= sprintf( \'<li><ul><li>%s:</li>%s</ul></li>\',
$taxonomy,
$li );
}
}
return sprintf( \'<ul>%s</ul>\', $html );
}
您可以通过以下方式进行调用:
echo get_the_current_tax_terms_wpse( get_the_ID() );
从模板中。