How to: Add a new menu section
-
If I want to create another bpmember section called “Test” in the navigation bar (not the admin-bar) what changes would I have to make to my theme?
My thoughts would be to add a new folder under “directories” in my theme folder called ‘Test’. (same place where the 3 other sections are located: Members, Groups & Blogs)
And id probably need to add something to the header.php as well where the navigation is setup?
Anything else? Can anyone tell me how to do this?
Thanks.
-
adding another menu link is just a simple html add on header.php…
but not sure about making another directory template. But I think it shouldn’t be that difficult.
Socialpreneur >
I guess its the header.php file in the bpmember theme that has to be edited and not the header.php in the home theme? Or should the change be added to both header.php files?
They almost look the same so whats the difference between the two?
Also how would the code look, there’s a section where it says:
Bpmember theme’s header.php:
<div id="header">
<h1 id="logo"><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php bp_site_name() ?></a></h1>
<ul id="nav">
<li<?php if ( bp_is_page( 'home' ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a></li>
<li<?php if ( bp_is_page( BP_HOME_BLOG_SLUG ) ) {?> class="selected"<?php } ?>><a href="<?php bp_home_blog_url() ?>" title="<?php _e( 'Blog', 'buddypress' ) ?>"><?php _e( 'Blog', 'buddypress' ) ?></a></li>
<li<?php if ( bp_is_page( BP_MEMBERS_SLUG ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_MEMBERS_SLUG ?>" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?></a></li>
<?php if ( function_exists( 'groups_install' ) ) { ?>
<li<?php if ( bp_is_page( BP_GROUPS_SLUG ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_GROUPS_SLUG ?>" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?></a></li>
<?php } ?>
<?php if ( function_exists( 'bp_blogs_install' ) ) { ?>
<li<?php if ( bp_is_page( BP_BLOGS_SLUG ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_BLOGS_SLUG ?>" title="<?php _e( 'Blogs', 'buddypress' ) ?>"><?php _e( 'Blogs', 'buddypress' ) ?></a></li>
<?php } ?>
<?php do_action( 'bp_nav_items' ); ?>
</ul>
</div>Its probably here the extra code would have to be added? I cant seem to get it to work.
Socialpreneur > I thought adding another menu link would require that i make another directory inside the bptheme ‘directory’ folder?
How come Members, Groups and Blogs has a directory then?
I still need some help on adding new menu links. Anyone?
me too, can somebody post code examples of how you can add new menu items to the nav so that the selected class works on the pages also.
Thanks,
Patrick
create a file called new-menu-item.php and put it in your mu-plugins folder then add this code to your file:
<?php
function add_test_to_main_menu() {
echo '<li <a href="http://yoursite.com/Url-of-test/">Test</a></li>';
}
add_action('bp_nav_items', 'add_test_to_main_menu');
?>This seems to be working for me now. As far as adding multiple items should the code be included in one file (ie new-menu-item.php) or should each snippet for each menu item be in a different php file? or does it matter?
Ok strike that last post, this method is still not working for me. I have another plugin installed which gets ruined once this file is uploaded to the mu-plugins folder, also when you add multiple menu items to the single php file, I run into the problem of the page not refreshing after posts are made. I guess we are still looking for a proper solution to this issue. Anybody feel free to comment.
there was a typo in my last post, the file should look like this instead
<?php
function add_test_to_main_menu() {
echo '<li> <a href="http://yoursite.com/Url-of-test/">Test</a></li>';
}
add_action('bp_nav_items', 'add_test_to_main_menu');
?>I forgot to add the > after <li
see if that works
and to add more than one you can just add a new function and then add_action at the end like this
<?php
function add_test1_to_main_menu() {
echo '<li> <a href="http://yoursite.com/Url-of-test1/">Test1</a></li>';
}
function add_test2_to_main_menu() {
echo '<li> <a href="http://yoursite.com/Url-of-test2/">Test2</a></li>';
}
add_action('bp_nav_items', 'add_test1_to_main_menu');
add_action('bp_nav_items', 'add_test2_to_main_menu');
?>Thanks for all your help Tutsie, we are getting closer to the solution. I am now having an issue where the selected class isn’t working on the highlighted page… but my plugin problem is solved and the page refreshes again… any ideas?
yeah I have that problem too, I think someone else is going to have to come to the rescue with that issue but Ill let you know if I find anything
Thanks Tutsie!
Can anyone maybe extend Tutsie’s code so the class=”selected” (menu link highlight) works??
Very good, thank you!!!
Has anybody solved this issue yet? Is there anywhere else we can get information on how to get the selected class functionality added to this fix.
Thanks
Patrick
I just added simple buttons via the header.php. This needs to be changed for both the homepage template and the user template header.php …
All I added was extra
example:
<li <?php if ( bp_is_page( 'home' ) ) {?> class="selected"<?php } ?>><a>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a></li><br /> <li <?php if ( bp_is_page( 'forum' ) ) {?> class="selected"<?php } ?>><a href="http://spoodle.co.nz/3/message/">Forum</a>
this comes out as: Home | Forum
To limit database queries you could simplify the navigation to just using simple code:
<ul <li><a href="http://spoodle.co.nz/3/">Home</a></li><br /> <li><a href="http://spoodle.co.nz/3/Blog/">Blog</a></li><br /> </ul>
which gives you: Home | Blog
etc etc anyway thats what i have done i’m sure you could make some complex buttons by playing around…
Nirok: If I goto your site http://spoodle.co.nz/3/ and I click the ‘Forum’ link, that link dosen’t come up as “selected / highlighted” like the other links.
We still need a solution on how to make it highlight when the link is active, just as when you click into https://buddypress.org/forums/.
- The topic ‘How to: Add a new menu section’ is closed to new replies.