我正在尝试以与获取术语名称相同的方式获取分类名称:$术语->名称-这可能吗?
但是$taxonomy->name不会显示任何内容$taxonomy单独显示slug,但我需要分类的标签/名称。
// get taxonomies terms links
function custom_taxonomies_terms_links() {
global $post, $post_id;
// get post by post id
$post = &get_post( $post->ID );
// get post type by post
$post_type = $post->post_type;
// get post type taxonomies
$taxonomies = get_object_taxonomies( $post_type );
$taxonomynames = get_queried_object();
$out = " <ul\'>";
foreach ( $taxonomies as $taxonomy ) {
$out .= "<li\'><span\'>" . $taxonomy->name . ": ";
$out .= "</span>";
// get the terms related to post
$terms = get_the_terms( $post->ID, $taxonomy );
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$out .= \'<a href="\' . $term->slug . \'">\' . $term->name . \'</a> \';
}
}
$out .= "</li>";
}
$out .= "</ul>";
return $out;
}