Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to: Add a new menu section

  • Avatar of Ezd
    Ezd
    Participant

    @ezd

    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.

Viewing 17 replies - 1 through 17 (of 17 total)
  • Avatar of wpmubp.org
    wpmubp
    Participant

    @takuya

    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.

    Avatar of Ezd
    Ezd
    Participant

    @ezd

    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.

    Avatar of Ezd
    Ezd
    Participant

    @ezd

    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?

    Avatar of Ezd
    Ezd
    Participant

    @ezd

    I still need some help on adding new menu links. Anyone?

    Avatar of Plunderpat808
    plunderpat808
    Participant

    @plunderpat808

    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

    Avatar of Tutsie
    Tutsie
    Participant

    @tutsie

    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');

    ?>

    Avatar of Plunderpat808
    plunderpat808
    Participant

    @plunderpat808

    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?

    Avatar of Plunderpat808
    plunderpat808
    Participant

    @plunderpat808

    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.

    Avatar of Tutsie
    Tutsie
    Participant

    @tutsie

    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

    Avatar of Tutsie
    Tutsie
    Participant

    @tutsie

    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');

    ?>

    Avatar of Plunderpat808
    plunderpat808
    Participant

    @plunderpat808

    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?

    Avatar of Tutsie
    Tutsie
    Participant

    @tutsie

    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

    Avatar of Ezd
    Ezd
    Participant

    @ezd

    Thanks Tutsie!

    Can anyone maybe extend Tutsie’s code so the class=”selected” (menu link highlight) works??

    Avatar of Internetado
    Internetado
    Participant

    @internetado

    @Tutsie

    Very good, thank you!!!

    Avatar of Plunderpat808
    plunderpat808
    Participant

    @plunderpat808

    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

    Avatar of Nirok
    Nirok
    Participant

    @nirok

    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>
    <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>
    <li><a href="http://spoodle.co.nz/3/Blog/">Blog</a></li>
    </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…

Avatar of Ezd
Ezd
Participant

@ezd

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 http://buddypress.org/forums/.

Viewing 17 replies - 1 through 17 (of 17 total)

You must be logged in to reply to this topic.