站点图标 度崩网-几度崩溃

WordPress美化 柒比贰主题菜单调用文章数量

WordPress美化 柒比贰主题菜单调用文章数量

Functions.php 文件添加,记得修改域名

/* */
function wt_get_category_count($cat_ID) {
    $category = get_category($cat_ID);
    return $category->count;
}
function zrz_add_has_children_to_nav_items_num( $items,$args ){
      if(isset($args->theme_location) && $args->theme_location == 'header-menu'){
      foreach ( $items as $item ){
     	$slug = str_replace('https://www.dungei.net/category/','',$item->url);
        $slug = str_replace('/','',$slug);
        $cat = get_category_by_slug($slug);
	$catID = $cat->term_id;
      
if( $catID){
         $a=wt_get_category_count($catID);
         $item->title.= ''.$a.'';
         }
       }
     }        
return $items; 
}
add_filter( 'wp_nav_menu_objects', 'zrz_add_has_children_to_nav_items_num',10,2 );

需要在 直接在 style.css 上添加

.num {
    position: absolute;
    top: 8px;
    left: 68%;
    color: #fff;
    border-radius: 8px;
    text-align: center;
    font-family: Calibri;
    background: #f16b6f;
    font-size: 12px;
    min-width: 32px;
	}
@media screen and (max-width:680px){
	.num {
    display:none;
}
}

本教程未测试,如果使用过程中有问题出现。请在评论区反馈