RIPRO主题美化-如何实现网站二级导航菜单统计文章数量 wordpress主题美化
教程开始
1、找到wp-content/themes/ripro/assets/css/diy.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;}}
2、找到wp-content/themes/ripro/functions.php将下面的内容整体复制进去并保存
在functions.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.= '<span class="num">'.$a.'</span>';
}
}
}
}
return $items;
}
add_filter( 'wp_nav_menu_objects', 'mysite_nav_items_num',10,2 );
效果样式
本文链接:http://78moban.cn/post/6994.html
版权声明:站内所有文章皆来自网络转载,只供模板演示使用,并无任何其它意义!