方法很简单和ripro主题一样,直接在主题目录下functions.php文件中添加以下代码
//导航栏目统计 function wt_get_category_count($cat_ID) { $category = get_category($cat_ID); return $category->count; } function 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.= '<span class="num">'.$a.'</span>'; } } } } return $items; } add_filter( 'wp_nav_menu_objects', 'nav_items_num',10,2 );
再将CSS代码粘贴到app.css文件保存
/*导航栏目统计*/ .num{position:absolute;top:8px;left:75%;color:#555;border-radius:8px;text-align:center;font-family:Calibri;background:#eee;font-size:12px;min-width:32px}