Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

James White
James White
6,159 Points

Question about wp_nav_menu

I installed this Foundation wp theme: https://github.com/drewsymo/Foundation. I'm trying to edit it and I have very little experience in creating and editing wp themes as it is.

What I want to do is on the top-nav bar is have some menu options on the left, and on the right have a dropdown with other menu options.

There's these lines:

<nav class="top-bar">
    <ul class="title-area">
        <li class="name"><h1><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo('name'); ?></a></h1></li>
        <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
    </ul>
    <section class="top-bar-section">
        <?php wp_nav_menu( array( 'theme_location' => 'header-menu', 'menu_class' => 'left', 'container' => '', 'fallback_cb' => 'foundation_page_menu', 'walker' => new foundation_navigation() ) ); ?>
    </section>
</nav>

The section class top-bar-section is what I believe I'm afterand I'm assuming the menu_class => left is what is giving the css class to pull the nav items to the left. How do I add other options into that section with a menu_class of right? Or is that possible?

Thanks!

Alexander Sobieski
Alexander Sobieski
6,555 Points

Hi James,

A couple things: 1) http://codex.wordpress.org/Function_Reference/wp_nav_menu has the down-low on all that fun stuff. the 'menu_class => left' is saying that all menu items will have a class of "left" added to them. The CSS that modifies that will be in the theme's stylesheets.

2) You can totally delete that whole wp-nav menu block of php, and code your own wp-nav menu. You don't have to use your theme's menu set-up.

3) For more moderate to advanced PhPers and WP people, there's the "Walker Nave Menu" class at the end. If you look that up, there is a way to create a new Walker Nave Menu object, and within that instance you can modify or replace how and what the wp nav menu function does. -- you could use php and/or javascript to do what you are looking to do.

4) OTHERWISE, instead of the wp-navmenu section, you can physically code links into the template. You'd lose the lovely nav menu feature that Wordpress has, but you'll get an exact customization to your own specs... and since, I'm assuming, it's your site, you know how to fix/edit it if you like. -- just a thought.