TSYBLOG.COM

ripro主题美化 · 二级导航菜单添加文章数量统计和美化小圆点

(先看效果图(也可点击本站顶部菜单查看)

%title插图%num

找到\ripro\functions.php 文件,在最下面添加以下代码:

//导航菜单增加文章统计
function wt_get_category_count($cat_ID) {
    $category = get_category($cat_ID);
    return $category->count;
}
function lanmitu_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', 'lanmitu_nav_items_num',10,2 );

2、找到\ripro\assets\css\diy.css 在最下面添加以下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;
}
/***二级导航前面小圆点***/
.lanse {
    box-sizing: border-box;
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    position: absolute;
    top: 50%;
	margin-left: 10px;
    margin-top: -6px;
    left: 0;
	border-color: #61e1b9;
	border: 3px solid #7a99f2;
}

.lvse {
    box-sizing: border-box;
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    position: absolute;
    top: 50%;
	margin-left: 10px;
    margin-top: -6px;
    left: 0;
	border-color: #61e1b9;
	border: 3px solid #70d7cf;
}
.huangse {
    box-sizing: border-box;
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    position: absolute;
    top: 50%;
	margin-left: 10px;
    margin-top: -6px;
    left: 0;
	border-color: #61e1b9;
	border: 3px solid #f5c745;
}
.hongse {
    box-sizing: border-box;
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    margin-left: 10px;
    margin-top: -6px;
    left: 0;
    border-color: #61e1b9;
    border: 3px solid #f1787f;
}
/***二级导航前面小圆点结束***/

3、导航前面添加小圆点,在后台-菜单里设置,如下图:

此区域内容需评论后可见

喜欢本文?
文章阅读
常见问题
免费下载或者VIP会员专享资源能否直接商用?
提示下载完成但无法解压?
投稿及掉连解决方法:

本站均测试后上架,保证所提供下载的资源的准确性、安全性和完整性。

如有链接无法下载、失效或广告,下方评论区留言,或联系客服处理,看到处理!

如果您也有好的资源或教程,您可以投稿发布,所得成本报酬归发布方所有!

17条回应

  1. 1232021-1-17 21:49

  2. 112021-3-8 11:32

    喜欢你

  3. 1112021-3-9 1:00

  4. www2021-5-18 12:49

  5. jjjb2021-5-20 11:01

    也做不

  6. meomii2021-8-25 9:54

  7. 3212021-9-3 21:11

  8. 我是2021-9-26 2:44

  9. wyx5672021-12-13 23:50

    喜欢你

  10. jgh2022-2-16 22:36

    转载请注明来源: https://tsyblog.com/6001.html

  11. jgh2022-2-16 22:37

  12. 1232022-2-18 1:41

    很666

  13. abo2022-5-9 18:37

  14. wi1963242022-6-28 2:51

  15. 34870951862022-9-12 9:18

    看看

  16. 嗷嗷嗷2023-3-10 17:04

    顶顶123

  17. 伟大的2023-5-25 17:21

    嗨哟