One site, 2 distinct sections: two different top nav menus?

I have a site that is in two distinct halves. I’d like the same template to apply to the whole site (from a look & feel perspective), but for each ‘half’ of the site to have its own top nav menu. No side menus are in use.

The home page is going to be a custom page that directs the user to one or other of the two sides.

Read More

How might I go about achieving this?

Many thanks

Austen

Related posts

Leave a Reply

3 comments

  1. The easiest solution would be to set a cookie. Then check what cookie the user have before you print the menu.

    Another solution would be to add a query variable so that the two halves have different urls, for example mysite.com/?half=A and mysite.com/?half=B. Then you check the query var before you print the menu. This solution would make it possible with permalinks for the two different halves. (and you can make the urls pretty if you want)

  2. Use a custom menu with wp_nav_menu(). Then check whether you’re on part one or part two:

    if ( ! is_home() || is_front_page() )
    {
        $args = array(); // Define your menu here
        $query_string = explode( '/', $_SERVER['REQUEST_URI'] );
    
        // You need to var_dump( $query_string ); 
        // to see which index/key is matching your requested query string part
        if ( 'PART_ONE' === $query_string[0] )
        {
            wp_nav_menu( array_merge( $args, array( 'menu' => 'MENU PART ONE' ) ) );
        }
        else
        {
            wp_nav_menu( array_merge( $args, array( 'menu' => 'MENU PART TWO' ) ) );
        }
    }
    
  3. I believe the simplest solution would be to create two nav menus in the WordPress backend, then load different headers based upon the page the visitor is on.

    Start by copying your header.php 2 times, giving your three header files. Example: header.php, headerA.php, headerB.php

    Now, open you original header.php and replace all the code with something like this:

    <?php
    if (is_page('contact')){
        <?php include(TEMPLATEPATH.'/headerA.php'); ?>
    }
    elseif (is_page('gallery')){
        <?php include(TEMPLATEPATH.'/headerB.php'); ?>
    }
    else {
        <?php include(TEMPLATEPATH.'/headerA.php'); ?>
    }
    ?>
    

    This will tell Wordress which header to load, based on the type of page the visitor is on.

    Also, make sure you load the correct menu in each header file using:

    <?php wp_nav_menu( array('menu' => 'Menu A )); ?>