我找到了这段代码,它可以工作:
<?php get_header(); ?>
<div id="job-listings">
<?php
$category = get_the_category();
$theName = $category[0]->name;
$theChild = $category[0]->cat_ID;
$subcats = get_categories(\'child_of=\' . $theChild);
foreach($subcats as $subcat) {
echo \'<h3>\' . $subcat->cat_name . \'</h3>\';
echo \'<ul>\';
$subcat_posts = get_posts(\'cat=\' . $subcat->cat_ID);
foreach($subcat_posts as $subcat_post) {
$postID = $subcat_post->ID;
echo \'<li>\';
echo \'<a href="\' . get_permalink($postID) . \'">\';
echo get_the_title($postID);
echo \'</a></li>\';
}
echo \'</ul>\';
} ?>
</div>
<?php get_footer(); ?>