Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cara Pakai:
- 1. Paste salah satu kode berikut di function.php, yang pertama simpel.
- 2. Bikin Custom menu. Tanpa custom menu tidak muncul menu post count-nya.
- Sumber: https://wordpress.stackexchange.com/questions/165333/how-to-add-category-post-count-in-main-navigation-menu
- add_filter('the_title', 'wpse165333_the_title', 10, 2);
- function wpse165333_the_title($title, $post_ID)
- {
- if( 'nav_menu_item' == get_post_type($post_ID) )
- {
- if( 'taxonomy' == get_post_meta($post_ID, '_menu_item_type', true) && 'category' == get_post_meta($post_ID, '_menu_item_object', true) )
- {
- $category = get_category( get_post_meta($post_ID, '_menu_item_object_id', true) );
- $title .= sprintf(' (%d)', $category->count);
- }
- }
- return $title;
- }
- Sumber: https://wordpress.stackexchange.com/questions/229767/show-posts-count-for-categories-and-tags-in-wp-nav-menu
- function ggstyle_menu_item_count( $output, $item, $depth, $args ) {
- // Check if the item is a Category or Custom Taxonomy
- if( $item->type == 'taxonomy' ) {
- $object = get_term($item->object_id, $item->object);
- // Check count, if more than 0 display count
- if($object->count > 0)
- $output .= "<span class='menu-item-count'> (".$object->count.")</span>";
- }
- return $output;
- }
- add_action( 'walker_nav_menu_start_el', 'ggstyle_menu_item_count', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement