排除两个父母获取_the_terms



这应该很简单,我期待学习如何做。

下面的代码仅排除顶级父。如何修改此代码以排除下一个级别?

eg:

我的分层术语是世界>国家>美国

我想展示美国,而不是世界或国家/地区

$terms = get_the_terms( $post->ID, 'From' );
if ( !empty( $terms ) ) {
    $output = array();
    foreach ( $terms as $term ){
        if( 0 != $term->parent )
            $output[] = '<a href="' . get_term_link( $term ) .'">' . $term->name . '</a>';
    }
    if( count( $output ) )
        echo '' . __('Categories:','om_theme') . '</b> ' . join( ", ", $output ) . '';
}
echo '' . __('Categories:','om_theme') . '</b> ' . end($output) . '';

相关内容

最新更新