您可以使用这样的东西来完全控制您的类别列表
global $wpdb;
$taxonomy = CUSTOM_CAT_TYPE; // in your case, it's categories
$table_prefix = $wpdb->prefix;
$wpcat_id = NULL;
//Fetch category
$wpcategories = (array) $wpdb->get_results("
SELECT * FROM {$table_prefix}terms, {$table_prefix}term_taxonomy
WHERE {$table_prefix}terms.term_id = {$table_prefix}term_taxonomy.term_id
AND {$table_prefix}term_taxonomy.taxonomy ='" . $taxonomy . "' and {$table_prefix}term_taxonomy.parent=0
ORDER BY {$table_prefix}terms.name ASC" );
foreach ($wpcategories as $wpcat) {
$name = $wpcat->name;
echo '<a href="'.$wpcat->slug.'"><img src="'.$wpcat->slug.'.png"/></a>';
}
如果你有父类别和子类别,你可以做这样的事情
foreach ($wpcategories as $wpcat) {
$name = $wpcat->name;
$termid = $wpcat->term_id; //parent category ID
$args = array(
'type' => POST_TYPE, //in normal case its post otherwise custom pist type
'child_of' => '',
'parent' => $termid, //parent category ID
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => $termid, //stop duplicate parent category
'include' => '',
'number' => '',
'taxonomy' => CUSTOM_CAT_TYPE, //categories in ur case
'pad_counts' => false);
$acb_cat = get_categories($args); //ALSO can SIMPLY USE this LINE and previous arguments
//Code for showing number of posts from subcategories you can do it for categories as you have get_categories output.
$postCount = 0;
foreach($acb_cat as $subcat)
{
$countposts = get_term($subcat->term_id,$taxonomy);
$postCount += $countposts->count;
}
echo '<a href="'.$wpcat->slug.'"><img src="'.$wpcat->slug.'.png"/></a>'.$postCount;
}