$post_type = $post->post_type;
$taxonomies = get_object_taxonomies( $post_type, 'objects' );
foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){
$terms = get_the_terms( $post->ID, $taxonomy_slug );
if ( ! empty( $terms ) ) {
$termname = esc_html( $terms[0]->name );
$termslug = esc_html( $terms[0]->slug );
$termlink = get_term_link($terms[0]);
$parent = $terms[0]->parent;
$parentlink = get_term_link($parent);
$parentterm = get_term( $parent, $taxonomy_slug );
$parentname = $parentterm->name;
}
}
if( !empty( $parentlink) ){echo '<a href="' . $parentlink . '">' . $parentname . '</a> ';}
评论区
发表新的留言
您可以留言提出您的疑问或建议。
您的留言得到回复时,会通过您填写的邮箱提醒您。