
1. 在functions.php里添加
[cc lang=”php”]function wt_get_category_count($cat_ID) {
$category = get_category($cat_ID);
return $category->count;
}
function mysite_nav_items_num( $items,$args ) {
if(isset($args->theme_location) && $args->theme_location == ‘menu-1’) {
foreach ( $items as $key=>$item ) {
if($item->object == ‘category’) {
//$cat = get_category_by_slug($slug);
$catID = isset($item->object_id) ? $item->object_id : false;
if($catID && $item->post_parent!=0) {
$a=wt_get_category_count($catID);
$items[$key]->title.= ‘‘.$a.’‘;
}
}
}
}
return $items;
}
add_filter( ‘wp_nav_menu_objects’, ‘mysite_nav_items_num’,10,2 );
[/cc]
2.diy.css 里添加
[cc lang=”css”].num{position: absolute;top: 8px;left: 68%;color: #555;border-radius: 8px;text-align: center;font-family: Calibri;background: #eee;font-size: 12px;min-width: 32px;}
@media screen and (max-width:680px){.num{display: none;}}
[/cc]
