I was trying to set up different menus based on what category "page" you were on using the built in Wordpress menu editor.
In my header file I set up:
<?php
if (is_home()) {
$menu = 'home';}
elseif($post->post_name='category-aviation'){
$menu = 'aviation';}
elseif($post->post_name='category-anti-terrorism'){
$menu = 'anti-terrorism';}
elseif($post->post_name='asbestos'){
$menu = 'asbestos';}
elseif($post->post_name='burn-pits'){
$menu = 'burn-pits';}
elseif($post->post_name='catastropic-injury'){
$menu = 'catastrophic-injury';}
elseif($post->post_name='medical'){
$menu = 'medical';}
elseif($post->post_name='securities'){
$menu = 'securities';}
//get_category_by_slug('aviation')
?>
And I was calling the menu like:
<?php wp_nav_menu( array( 'theme_location' => "$menu" , 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
I set up the functions.php file with:
function show_posts_nav() {
global $wp_query;
return ($wp_query->max_num_pages > 1);
add_action( 'init', 'register_my_menus' );
}
if ( function_exists( 'register_nav_menus' ) ) {
register_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'
)
);
}
None of the menus are showing up however. Am I doing something wrong here? I know the body class is set to "class="archive category category-aviation category-5 logged-in admin-bar" when I am on the aviation page.
is_category()
? example:elseif( is_category('aviation') ){ $menu = 'aviation';}