简体   繁体   English

Wordpress 显示当前类别页面的子术语?

[英]Wordpress Display Child Term of the Current Category Page?

Hi I am trying to display the child term of the current post category page.嗨,我正在尝试显示当前帖子类别页面的子术语。 However I can figure out what am missing here.但是我可以弄清楚这里缺少什么。 Thanks谢谢

<?php
$current_tax = get_query_var( 'category' );
$current_term = get_queried_object()->term_id;

$child_terms = get_terms( array('category' => $current_tax,
                                'child_of' => $current_term,
                                'orderby' => 'name' ));
if ( ! empty( $child_terms ) && ! is_wp_error( $child_terms ) ) {

    echo '<div class="post-index__cate">';
    foreach( $child_terms as $child ) {


        printf( '<a class="category-name" href="%s">', get_term_link( $child, $child->taxonomy ));

        echo $child->name. '</a>';

    }
    echo '</div>';
}
?>

In your code the taxonomy should be “category”, so your arguments for get_terms() should have “taxonomy” => “category”.在您的代码中,分类法应为“类别”,因此 get_terms() 的参数应为“分类法”=>“类别”。 $current_tax is irrelevant in this code then. $current_tax 在这段代码中是无关紧要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM