3

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.

How might I go about achieving this?

Many thanks

Austen

3 Answers 3

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)

1
  • 1
    Thanks Offroff - Travis' suggestion might fit the bill for me on this problem. Thanks for taking the time. Austen Apr 22, 2012 at 16:28
1

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' ) ) );
    }
}
1
  • 1
    Thanks Kaiser. I'll give Travis' idea a run, and refer back to this if it doesn't fit the bill. Austen Apr 22, 2012 at 16:28
1

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 )); ?>
3
  • 1
    Thanks Travis - I like the sound of this idea. I'll give it a try. Austen. Apr 22, 2012 at 16:27
  • 2
    This would be a lot easier to manage by just putting the two navigation menus inside the conditional rather than maintaining multiple header.php files. If page is ... Menu a, else menu b. Apr 23, 2012 at 3:30
  • +1 on the comment Christopher. That is simpler if the nav menu is the only thing changed between the different headers. Apr 23, 2012 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.