Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Adding menu items to the admin bar (80 posts)

Started 1 year, 10 months ago by: Jens Wedin

  • Profile picture of Jens Wedin Jens Wedin said 1 year, 10 months ago:

    Others have asked, but I haven’t found an easy solution to make dropdown menu items from my pages and post categories in the Buddypress admin bar? I want to use the bar as my main navigation menu.

  • Profile picture of Chau kar Chau kar said 1 year, 10 months ago:

    function pages(){
    ?>

    <li><a href=”#”>Pages</a>
    <ul>
    <li><a href=”http://www.animeonsen.com”>Home</a></li>
    <li><a href=”http://www.animeonsen.com/about”>About</a></li>
    <li><a href=”http://www.animeonsen.com/support-us”>Support us</a></li>
    <li><a href=”http://www.animeonsen.com/advertise”>Advertise</a></li>
    <li><a href=”http://www.animeonsen.com/anime-stores”>Anime stores</a></li>
    <li><a href=”http://www.animeonsen.com/friends”>Friends</a></li>
    <li><a href=”http://www.animeonsen.com/archives”>Archives</a></li>
    <li><a href=”http://www.animeonsen.com/contact”>Contact</a></li>
    </ul>
    </li>

    <?php
    }
    add_action( ‘bp_adminbar_menus’, ‘pages’, 15 );

    That is what I did. (Sorry don’t know how to post the code as normal text!!!) It is not the best solution, but it works! Let me know if you figured out a better way.

    Mod Edit// Less than angle brackets escaped – BB tags do not work .

  • Profile picture of Jens Wedin Jens Wedin said 1 year, 10 months ago:

    Here is an snippet that should be added to the bp-functions.php (located in the plugins folder)

    http://pastebin.com/5K1rrVvL

    Check my site to see how it looks: http://www.chwisgi.com

  • Profile picture of alanchrishughes alanchrishughes said 1 year, 9 months ago:

    @JediSthlm are you saing you have to create a bp-functions.php file and put it in your plugins folder? Cause I don’t see one already created anywhere.

  • Profile picture of @mercime @mercime said 1 year, 9 months ago:

    @alanchrishughes yes create a blank bp-custom.php (not bp-functions.php) and paste on the code. Save and upload the bp-custom.php file to wp-content/plugins/ folder

  • Profile picture of alanchrishughes alanchrishughes said 1 year, 9 months ago:

    @mercime thanks! I’ve been trying to figure that out for a while now. Is there a way to add a link without the drop down arrow? I don’t see any class or id added to it so I don’t know how it is picking it up.

  • Profile picture of pcwriter pcwriter said 1 year, 9 months ago:

    @Jens Wedin @alanchrishughes

    I was looking for a way to include all navigation links in one navbar. Jens’ code snippet is brilliantly simple. Thanks!
    The only drawback is you have to add links manually to get them to appear in the adminbar.

    I’ve modified the code (borrowing inspiration from a snippet previously written by @David Lewis) so that:
    1 – all “standard” BP Directory links appear automatically in their own dropdown;
    2 – all BP plugin directories (Links, Gallery, etc) are automatically added to that dropdown;
    3 – all WP pages are added automatically to the adminbar;
    4 – all added WP pages respect whatever page order is set in the WP-Dashboard.

    The code is here: http://pastebin.com/8FJmcgRF

    To ensure that unwanted pages DON’T show up in the adminbar navigation (password-protected, Thank You pages, etc), install the Exclude Pages plugin:

    http://wordpress.org/extend/plugins/exclude-pages/

  • Profile picture of rickkumar rickkumar said 1 year, 9 months ago:

    @pcwriter
    You should release this as a plugin.

  • Profile picture of pcwriter pcwriter said 1 year, 9 months ago:

    @rickkumar

    Great idea! Hmm… my first REAL contribution. Cool :-)
    There’s gotta be a “How to Build a Plugin” tutorial around here somewhere…

  • Profile picture of rickkumar rickkumar said 1 year, 9 months ago:

    @pcwriter

    May be this can help:

    Creating a Custom BuddyPress Component

    http://codex.buddypress.org/how-to-guides/creating-a-custom-buddypress-component/

  • Profile picture of pcwriter pcwriter said 1 year, 9 months ago:

    @rickkumar

    Yup, I’m there… and here: http://codex.wordpress.org/Writing_a_Plugin

  • Profile picture of rickkumar rickkumar said 1 year, 9 months ago:

    Cool :)

  • Profile picture of alanchrishughes alanchrishughes said 1 year, 9 months ago:

    There’s got to be a much more logical way of doing this, we’re sitting here talking about adding a couple a hrefs like it’s rocket science and requires all kinds of php code. I know it takes some php to tell if a user is logged in or not and notifications, but its like the entire bar is held hostage to these few links.

  • Profile picture of pcwriter pcwriter said 1 year, 9 months ago:

    @alanchrishughes

    The code I’ve posted is actually quite simple when you get right down to it. Simple yet powerful. It does everything you want a dropdown menu to do, and it does it all automatically behind the scenes.

    It starts by identifying what links belong to dynamically generated BP directories and adds those to the adminbar in a Community dropdown. To that same dropdown, It then adds all BP directories that are created by any BP plugins you may have installed.

    It then identifies all WP pages and adds them to the adminbar also. The really cool part is no matter how you’ve set up your WP page hierarchy and page order in your dashboard, that will be preserved in hierarchical dropdowns like the following example:

    Parent page 1
    - Child page 1
    – Grand-child page 1
    - Child page 2
    - Child page 3…

    Go ahead, give it a whirl. Copy the code to bp-custom.php and upload to your plugins folder. No need to activate anything; Buddypress will recognize and execute the code.

    Take a look at my homepage: http://nowrecovery.com/

    The first dropdown is all Buddypress. The ones after it are all WP. If you create an account and login, you’ll see all the adminbar goodies appear to the left and bump everything else to the right.

  • Profile picture of Hugo Hugo said 1 year, 9 months ago:

    @pcwriter
    There is a need at present for dashboard links if one is running WP 3.0 single blog (unless one wants to have to ad the WP meta or type at address bar) I keep a function that allows me to add to adminbar links similar to that which you describe.

    You may like to consider a twist or variation on your code to include the new WP 3.0 nav menus?

    This example would add the ability for users to add / construct menus from the dashboard and place them on the adminbar:

    http://pastebin.com/qJwURYxm

    It’s not checked as such and names need adjusting etc.