Outlining your concept
As far as i can see, you want to do the following:
- Check if there is more than one page (
$GLOBALS['wp_query']->max_num_pages > 1
) - If
TRUE
, add your nav menus
The concept fails in some points (more explanation at the end of the answer):
- You’re questioning too early if there’s more than one page. (Your idea really is to only show these menus if you’re on page 2 of a paginated archive?)
- You’re looking into
$post->post_name
without a) having the data available from the global b) outside the loop and c) from the wrong global
Make your life easier
In your functions.php
file you can add the menu like this:
function wpse19269_add_nav_menus()
{
add_theme_support( 'menus' );
$nav_menus = array(
'home' => 'The Home Menu',
'aviation' => 'Aviation',
'anti-terrorism' => 'Anti-Terrorism',
'asbestos' => 'Asbestos',
'burn-pits' => 'Burn Pits',
'catastrophic-injury' => 'Catastrophic Injury',
'medical' => 'Medical',
'securities' => 'Securities'
);
register_nav_menus( $nav_menus );
}
add_action( 'init', 'wpse19269_add_nav_menus', 20 );
If you’re using the functions.php
file, you can write your own custom functions and avoid cluttering your thems files:
function wpse19269_show_nav_menus()
{
$menu = ''; // Set a value to avoid errors if no condition is met
if ( is_home() )
{
$menu = 'home';
}
elseif( is_category('some_category') )
{
$menu = 'whatever';
}
elseif
{
// and so on...
}
// Nav Menu
wp_nav_menu( array(
'theme-location' => $location
,'menu' => 'top-nav'
,'menu_id' => 'top-nav'
,'container' => false
,'container_class' => 'menu-header'
) );
}
// Use it in your theme like this:
// wpse19269_show_nav_menus();
After reading through your snippets, I think it’s best to explain some basic things:
Global Variables
If you want to access global
available $variables
, you’ll have to first call them as global $whatever
before you use it inside your function.
Example:
function the_example()
{
global $post; // Now we have the global data available in the function
echo $post->post_title; // This is the post title - must be used inside the loop
}
You can read here more about it.
Interacting with data in hooks
Please take a look at the Plugin API/Action Reference to see when $wp_query
is ready and available. You call on the init
hook is too early.
Conditional Tags
Use other Conditional Tags, like is_category('see codex link for more information');
.
Some other notes regarding your code:
wp_nav_menu( array( 'theme_location' => "$menu" ...
should be written without the "
.
WordPress functions
You don’t have to question if ( function_exists('some_native_wp_fn') ) {
, because it will exist. If doesn’t exist anymore, you’ll get a depracated
notice that tells you about it. If you question the existance you suppress the notice and won’t be able to fix it (or have a hard time finding it).