使用以下代码可以帮助您解决问题。
只需在$term\\u id变量中传递父类别的id
<?php
$term_id = ; // id for the parent category
$taxonomy_name = \'category\';
$termchildren = get_term_children( $term_id, $taxonomy_name );
foreach ( $termchildren as $child ) :
$term = get_term_by( \'id\', $child, $taxonomy_name );
?>
<h3><a href="<?php echo get_term_link; ?>"><?php echo $term->name; ?></a></h3>
<ul>
<?php
$args= array(\'cat\'=>$child,
\'posts_per_page\'=>6
);
$loop= new WP_query($args);
if( $loop->have_posts()):while($loop->have_posts()):$loop->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
endif;
?>
</ul>
<?php
endforeach;
?>