我如何列出当前类别的子类别列表。
我会尝试 get_categories 代码,但我不能。
像那样;
$args = array('child_of' => term_id );
$categories = get_categories( $args );
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
最佳答案
将 $args 替换为:
$current_cat = get_queried_object();
$args = array( 'child_of' => $current_cat->term_id, );
关于php - Wordpress 当前类别的子类别列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21563667/