get_the_category()
get_categories()
get_category_link()
<?php
echo \'<ul>\';
foreach(get_the_category() as $cat) {
echo \'<li><a href="\'.get_category_link($cat->term_id).\'">\'.$cat->name.\'</a>\';
$sub_cats = get_categories(\'parent=\'.$cat->term_id.\'&hide_empty=0\');
if($sub_cats) {
echo \'<ul>\';
foreach($sub_cats as $sub_cat) {
echo \'<li><a href="\'.get_category_link($sub_cat->term_id).\'">\'.$sub_cat->name.\'</a></li>\';
}
echo \'</ul>\';
echo \'</li>\';
}
}
echo \'</ul>\';
?>
编辑:对于类别存档中的子类别列表,请尝试以下代码:
<?php
$cat = get_query_var(\'cat\');
$cat_list = wp_list_categories(\'child_of=\'.$cat.\'&hide_empty=0&title_li=&echo=0\');
if($cat_list) {
echo \'Sub-category List <ul>\';
echo $cat_list;
echo \'</ul>\';
}
?>
wp_list_categories()