下面是一个使用类别而不是页面的示例,但您可以使用父级信息查询信息within 另一个循环:
// checking current taxonomy to see if it has child categories if it doesn\'t then we\'re out of sub categories and should show the current categories products
$args = array(
\'type\' => $taxfunc_post_type,
\'hide_empty\' => 1,
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'taxonomy\' => $taxfunc_tax_name
);
$categories = get_categories($args);
$categories = wp_list_filter($categories,array(\'parent\'=> $term_id));
foreach($categories as $category) {
// setup the cateogory ID
$cat_id = $category->term_id;
// Get category name
$cat_name = $category->name;
// Get category count
$cat_count = $category->count;
//get the category url
$cat_url = get_term_link( $category->slug, $taxfunc_tax_name );
echo \'<div class="cat-block">\';
echo \'<header>\';
echo "<h3>";
echo $cat_name;
echo "</h3>";
if ($cat_count > 0) {
echo \'<a href="\'.$cat_url.\'">\';
printf( _n(\'1 profile\', \'%s profiles\', $cat_count,\'mouldings\' ),$cat_count );
echo \'</a>\';
}
$subcat_args = array(
\'type\' => $taxfunc_post_type,
\'hide_empty\' => 1,
\'orderby\' => \'name\',
\'child_of\' => $cat_id,
\'order\' => \'ASC\',
\'taxonomy\' => $taxfunc_tax_name,
\'pad_counts\' => 1
);
$subcategories = get_categories($subcat_args);
$subcat_count = count($subcategories);
if ($subcat_count > 0) { echo \' <a href="\'.$cat_url.\'">\'; printf( _n(\'1 subcategory\', \'%s subcategories\', $subcat_count,\'mouldings\' ),$subcat_count ); echo \'</a>\'; }
echo \' <a class="view-all" href="\'.$cat_url.\'">\'.__(\'View all\',\'mouldings\').\'</a>\';
echo \'</header>\';
echo \'</div>\';
}
在上面,我指定
child_of
父类别的参数。如果有帮助,请告诉我。