treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress Multiple Menus

  • I have been asking Mr Google for help but hours spent in front of the screen didn't solve my problem clearly (by which I mean I'm a beginner and understand simple language only ;))

    I have a WP website with a menu at the top (ex. 1, 2, 3, 4)
    I would like to have a separate menu (5, 6, 7, 8) when I'm on page 4.

    Do you know any simple way of going about it? :)
  • You want to change your main navigation when you switch pages? Simply due to usability I highly recommend you not do that.

    But perhaps I'm not understanding you correctly! Perhaps you want a sub-navigation to show under it?
  • You understand what I mean - I want a different navigation when I switch pages.

    To make it clear - it is a page of a local church and I want a subpage for the youth ministry. This is why I want to change the navigation from the main to one connected with the youth only (separate gallery, news, etc.) and still I want it to work under the same domain and layout.

    Any ideas?
  • I've done something similar. WP 3.0 makes it quite a bit easier with the built in menus.

    Take a look at the TwentyTen theme and you can probably pick apart what you'll need to do. The primary menu that is setup like this:


    <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>


    So inside of WP, you'll define several menus (primary being the main one, and name subsequent menus accordingly).

    Honestly, it's a bit of a pain because you end up needing to pull the menu array out of the header.php file, and now begin defining it within the actual page files (page.php, index.php, etc). So on those pages you navigate to, you'll setup a custom template and you will use your 2nd, 3rd or 4th navigation array within those custom templated pages.

    But it did end up working wonderfully for my particular project.
  • And what about a conditional?
  • For example:


    <?php 
    if ( is_page('page_with_second_menu') ) {wp_nav_menu('menu' => 'menu-second-whatever-the-name-is');

    }
    ?>


    I have come across such things and I'm wondering how to make it work.
  • I haven't done that but I can't see why it wouldn't work.

    The reason I didn't go that direction was because of expandability. With a custom page, I could add a new page and have the menu follow.

    Using a conditional statement, let's say you add pages in the future. You would need to go back into the header.php and alter which pages will bring in the alternative menu.

    Maybe there is some more advanced magic that I'm not quite there with, but that was my logic at the time :P
  • Custom post types?

    That second section could be custom post types yeah?

    Codex

    So, you could set up a custom post type for your youth pages, a "single-type" template for custom posts and then call a custom header.php from that custom post single template that contains the navigation menu.

    Whenever a post is made by youth, it will be made on the custom post type "youth" (not page, or post, there will be a new option in the dashboard for "youth" posts or whatever you decide to call it) .

    Hope this makes sense to you.
  • It makes sense but I still have no idea how to go about it ;)
  • How often are these pages going to be added? And will the menus be changing quite a bit?
  • I made it!

    1. I added a new menu in functions.php in my theme.
    2. Then I created a new template (by simply copying page.php) where I replaced the name of the menu with the new one.
    3. Finally using Appearance -> Menu I created a new menu and in widgets I used my new custom menu.

    Now when I use any page connected with the youth I simply use the template.

    That was all I needed and didn't know it could be that simple :)

    Thank you all for your help!