How can I show different menu for different pages?

I have a website that has a main menu(Top-Horizontal) like this:

Main menu
 - Home
 - About Us
 - contact us

On Home page I have a link to “Company” page like this www.xyz.com/company.

Read More

When I am on this company page I want my website to chnage my menu items and use this:

Different menu
 - Home (same Home page link that will take user to www.xyz.com)
 - promoters
 - Gallery
 - Maps

I think i can do this using wordpress Conditional_Tags, but really dont know how should I start.

Related posts

Leave a Reply

5 comments

  1. You can try it this way. Now we are talking about pages you can set up a separate template for the page that needs a different menu. This where WordPress’s newer menu feature is really nice.

    First if you are using the newer menu feature of WordPress place this in place of your current menu:

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

    Next put this at the top of the template file that you are going to use for the page. This tells WordPress that this is a page template.

    <?php
    /*
     Template Name: Name your template here
    */
    ?>
    

    Then place this in your template where your menu should go for this template:

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

    Now we have to make sure that they will be activated. In your theme’s functions.php file you will need to place this:

    // This theme uses wp_nav_menu() in two locations.  
    register_nav_menus( array(  
      'primary' => __( 'Primary Navigation', 'your_theme_name' ),  
      'template_menu' => __('Template Navigation', 'your_theme_name')  
    ) ); 
    

    Once this is all done all you need to do is go to your dashboard > Appearance > Menu
    and create your menus there. Once created save then on the left it will give you the option of where to place which menu where via the drop downs.

    After all this is set up when you set up a new page all you have to do is select the template you want to use.

    I hope this helps if you have questions just ask.

  2. Diferent menu in diferents pages using custom field in page
    –> functions.php

    function shortcode_nav_menu_args( $args = '' ) {
        //if exist custom fiel cp_menu in page gets the id of menu (number)
        //else gets the default menu
        $menu = get_post_meta(get_the_ID(), 'cp_menu', true);
        if(isset($menu)) { 
            $args['menu'] = $menu; 
        }
        return $args;
    }
    add_filter( 'wp_nav_menu_args', 'shortcode_nav_menu_args' );
    
  3. Conditional tags would liekly be the way froward. How are you calling your menu? wp_list_pages() I assume?

    If so, you can make use of the exclude argument, using something like below (obviously tweek the page numbers and the conditional tags to your needs) –

    <?php
    if(is_front_page()) :
        $exclude = '10,11,12';
    elseif(is_page(15)) :
        $exclude = '1,2,3';
    endif;
    wp_list_pages('title_li=&depth=1&exclude=' . $exclude);
    ?>