[Resolved] Add Count Near Nav Menu
-
Hello,
I am trying to find a solution for 2 weeks. Please help me to fix that.
I want to show message and notification count near nav menu.
I found that we can show counts of message and notification with following php codes:
<?php echo bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );?> <?php bp_total_unread_messages_count() ?>
But i couldnt add this codes in menu. I want to change menu like
Forum Profile Message Notification Contact Blog
to =>
Forum Profile (5) Message (12) Notification Contact BlogSorry for that but i dont know php well. My website : http://www.pckopat.net
Thanks For Your Helps
-
Please help me to fix this. I couldnt find a solution
Add this to bp-custom.php and give a try ! Should show at the left of the logout button on Buddy theme nav bar
function my_nav_menu_notif_counter($menu) { $url = bp_core_get_user_domain(bp_loggedin_user_id()) .'notifications/'; // condition: user must be loggedin if (!is_user_logged_in()) return $menu; else $notif = '<li><a href=" ' .$url. ' ">Notif ['. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .']</a></li>'; $menu = $menu . $notif; return $menu; } add_filter( 'wp_nav_menu_items', 'my_nav_menu_notif_counter' );
man you are perfect π it works. Can we add code for messages and friends count?
Yes you can, but why would you do that as all those counters are already in the user menu (on top right, under Howdy) and on each profile ? Tsssss…., but you’re the boss ! π
To count friends use
friends_get_friend_count_for_user( bp_loggedin_user_id() );
To count messages usebp_get_total_unread_messages_count( bp_loggedin_user_id() )
Complete solutionfunction my_counter_nav_menu($menu) { $notif_url = bp_core_get_user_domain(bp_loggedin_user_id()) .'notifications/'; $friends_url = bp_core_get_user_domain(bp_loggedin_user_id()) .'friends/'; $msg_url = bp_core_get_user_domain(bp_loggedin_user_id()) .'messages/'; if (!is_user_logged_in()) return $menu; else $notif = ' <li><a href=" ' .$notif_url. ' ">Notif ['. bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ) .']</a></li> <li><a href=" ' .$friends_url. ' ">Friends ['. friends_get_friend_count_for_user( bp_loggedin_user_id() ) .']</a></li> <li><a href=" ' .$msg_url. ' ">Messages ['. bp_get_total_unread_messages_count( bp_loggedin_user_id() ) .']</a></li> '; $menu = $menu . $notif; return $menu; } add_filter( 'wp_nav_menu_items', 'my_counter_nav_menu' );
Bu yardΔ±m olabilir ! π
@danbp you are my hero. i tried to find this code for 2 weeks π you solved that. my theme doesnt contain user menu. So i need to add count of notification. Lastly how can we move this menu items left side of menu?
I tested the snippet on Buddy theme, so i’m pretty sure you have a user menu. This menu is on WP’s Toolbar. You see it when you’re logged in.
To choose an item position, you have to do it differently, as explained here:
[Resolved] Position Notification Counter Bubble after Specific Navigation Tab ID
For more about menu handling and functions, see WP Codex, as this is not really related to BuddyPress. Now it’s your turn to work a little !
ah you mean admin bar:) i dont want to use that. because i dont want 2 menu on header. You saved my time. Thanks for helping again. i will work on this on code
I just tried your function and its working fine but the only problem is that its adding menu items in all wordpress menus.
Is there anyway to add only in a specific menu instead of all menus?
Tesekkurler!
- The topic ‘[Resolved] Add Count Near Nav Menu’ is closed to new replies.