BuddyDev

Search

[Resolved] Adding nav items to a secondary navigation the right way

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

    Hi there, I have created a secondary navigation after_header using a hook element inserting some of my object-nav.item-list-tabs individually like the code below, containing links for Recent Visitors, Search and Messages.

    It is working, but I’m not sure if this is the right way of doing it.

    Could I instead insert a function like bp_core_new_nav_item (not working) from bp-core-buddybar.php instead of adding each link individually?

    Which is the right approach of doing that?

    Regards
    Carsten

    Content of the after_header hook element:

    <div class="grid-container sub-navigation grid-parent">
        <ul>
     
    			
    			<li id="visitors-personal-li">
    	<a  href="https://domain/members/me/visitors/" id="user-visitors" class="menu-item menu-item-type-post_type menu-item-object-post messages-personal-li button" >
    		
    		Visits <span class="count"><?php echo visitors_get_unique_visitors_count( bp_loggedin_user_id() ); ?> </span> 
    	</a>
    
    	</li>			
    			
    			
    			<a class="button" href="https://domain/search">Søg</a> 
    			
    
    			<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"><?php echo bp_get_total_unread_messages_count( bp_loggedin_user_id() );?></span>
                </a>
    				
            </li>     
    
    			
    			</ul>
    </div>
  • Keymaster
    (BuddyDev Team)
    Posts: 24611
    Brajesh Singh on #30997

    Hi Carsten,
    Thank you for the question.

    My suggestion will be to register a nav location(WordPress nav)
    https://developer.wordpress.org/reference/functions/register_nav_menu/

    and then using BuddyPress nav items(You can enable it from screen options on the menu page).

    That will save you any custom coding.

    Regards
    Brajesh

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

    Hi Brajesh, thanks for the clarification, this function is new to me, I will check this out.

    So I should not use the bp_get_displayed_user_nav() template tag?

    ‘and then using BuddyPress nav items(You can enable it from screen options on the menu page).’

    Which menu page are you referring to?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24611
    Brajesh Singh on #31008

    Hi Carsten,
    You are welcome.

    I am referring to WordPress admin menu management page.

    The problem with bp_get_displayed_user_nav is it will only list correctly if you are on a user’s profile.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved