BuddyDev

Search

[Resolved] Adding message count to Messages in a hook element

  • Participant
    Level: Yogi
    Posts: 1112
    calu on #29152

    Hi there, I have added messages in a sub-navigation hook element,and I want to add the message count as well.

    But I don’t know which value I should add for it to display. Can you help me with information, where the count is populated and which to use?

    <div class="grid-container sub-navigation grid-parent">
        <ul>
            <li id="messages-personal-li" >
                <a href="https://domain/members/me/messages/" id="user-messages" class="menu-item menu-item-type-post_type menu-item-object-post messages-personal-li button">
            Messages <span class="count"></span>
                </a>
            </li>
        </ul>
    </div>

    Thanks in advance
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #29170

    Hi,
    You can use the following code

    
    <?php echo bp_get_total_unread_messages_count( $user_id );?>
    

    Where you can use following for user id

    
    
    bp_loggedin_user_id(); // of the logged in user
    bp_displayed_user_id(); //  of the displayed user
    bp_get_member_user_id();// in members loop
    
    

    Depending on the context.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1112
    calu on #29209

    Hi Brajesh, thank you very much, again, for your valuable help, it’s working perfectly.

    Can I ask you to give me with the corresponding code for the visitors count?

    Thanks again

    Carsten

  • Participant
    Level: Yogi
    Posts: 1112
    calu on #29212

    Hi Brajesh, I think I found the right function

    <?php echo visitors_get_visit_count( $user_id ); ?>

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #29218

    Hi Carsten,
    Yes, that is the correct function.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1112
    calu on #29220

    Hi Brajesh, thanks, I found out that visitors_get_unique_visitors_count must be the correct one, or?

    One more question to this markup of the class below, which is probably not correct, It seems like defining the class below is redundant, as it has no effect?

    
    
    <li id="visitors-personal-li">
    	<a  href="https://domain/members/me/visitors/" id="user-visitors" class="recent-visitors-for-buddypress-profile" >
    		
    		Besøg <span class="count"></span> 
    	</a>
    
    <?php echo visitors_get_unique_visitors_count( bp_loggedin_user_id() ); ?> 
    	</li>
    
    

    The correct class must be something like the one for messages defining the button:

    class="menu-item menu-item-type-post_type menu-item-object-post messages-personal-li button"

    but I don’t know where to look it up?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #29233

    Hi Carsten,
    Both the functions are correct. Depends on your need. One provides unique count while other provide total count(including repeated visits).

    About the nav, I am sorry but I am not in a position to assist you. I do not think I understand the context well to assist you.

    You are most probably doing it for a custom theme and a lot of markup will depend on what the theme expects.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1112
    calu on #29236

    Hi Brajesh, that’s fine, thanks for all your help with the functions.

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #29242

    Thank you.

The topic ‘ [Resolved] Adding message count to Messages in a hook element’ is closed to new replies.

This topic is: resolved