• James posted an update 1 year, 3 months ago

    Here is a good if statement for echoing out the number of notifications a user has in buddypress and IF the count is 0 then nothing is displayed. This is useful for adding to your header.php as a kind of bubble that can appear next to an icon or something linking to your notifications page to let users know that they have a new notification just like on facebook.

    $notificationcount = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
    if ( $count > 0 ) {
    echo $notificationcount;
    } else {
    // nothing is displayed if the count is 0
    }

    You can change “bp_notifications_get_unread_notification_count” to adapt this code to count other things for example “bp_friend_get_total_requests_count” to get the users pending friend request count or you could even use “bp_get_total_unread_messages_count” to get the number of unread messages a user has! (Note if you use “bp_total_unread_messages_count ” without the get buddypress will simply ignore your if statement and will echo 0 no matter what.)