In a child theme we’ve added new template parts for the following files in order to select a different menu based on category.
child-theme/parts/menu-mobile.php
<?php
if (is_category(array(433,1738)))
{
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_class'=> 'td-mobile-main-menu',
'fallback_cb' => 'td_wp_no_mobile_menu',
'link_after' => '<i class="td-icon-menu-right td-element-after"></i>',
'walker' => new td_walker_mobile_menu()
));
}
elseif ( is_category(array(8704,17723,17717,17718,17724,17721,17720,17719,18809,18810,28327)) || in_category(array(8704,17723,17717,17718,17724,17721,17720,17719,18809,18810,28327)) || is_page(array(92484,92558,96207)) )
{
wp_nav_menu(array(
'theme_location' => 'header-menu-mobile-CUSTOM',
'menu_class'=> 'td-mobile-main-menu',
'fallback_cb' => 'td_wp_no_mobile_menu',
'link_after' => '<i class="td-icon-menu-right td-element-after"></i>',
'walker' => new td_walker_mobile_menu()
));
}
else
{
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_class'=> 'td-mobile-main-menu',
'fallback_cb' => 'td_wp_no_mobile_menu',
'link_after' => '<i class="td-icon-menu-right td-element-after"></i>',
'walker' => new td_walker_mobile_menu()
));
}
//if no menu
function td_wp_no_mobile_menu() {
//this is the default menu
echo '<ul class="">';
echo '<li class="menu-item-first">Click here - to use the wp menu builder';
echo '';
}
?>
and
child-theme/parts/header/header-menu.php
<?php
if (is_category(array(433,1738)))
{
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_class'=> 'sf-menu',
'fallback_cb' => 'td_wp_page_menu',
'walker' => new td_tagdiv_walker_nav_menu()
));
}
elseif ( is_category(array(8704,17723,17717,17718,17724,17721,17720,17719,18809,18810,28327)) || in_category(array(8704,17723,17717,17718,17724,17721,17720,17719,18809,18810,28327)) || is_page(array(92484,92558,96207)) )
{
wp_nav_menu(array(
'theme_location' => 'header-menu-mcn',
'menu_class'=> 'sf-menu',
'fallback_cb' => 'td_wp_page_menu',
'walker' => new td_tagdiv_walker_nav_menu()
));
}
else
{
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_class'=> 'sf-menu',
'fallback_cb' => 'td_wp_page_menu',
'walker' => new td_tagdiv_walker_nav_menu()
));
}
//if no menu
function td_wp_page_menu() {
//this is the default menu
echo '<ul class="sf-menu">';
echo '<li class="menu-item-first">Click here - to select or create a menu';
echo '';
}
?>
All that we’ve changed is the ‘theme_location’ in both files to load a different wp_nav_menu.
Everything works fine except for the css, drop down menu’s have no style and the height of links isn’t the full navigation bar height. Does the theme_location have any influence on the styling of the menu items?
Thanks
Matt
Hello,
Css is not dependent on the theme location but rather the classes and id’s of the elements.
There is another way of doing it however as the theme already allows this by using cloud library templates for your categories. You can use a different template with a different menu for each category. Use the cloud library, header manager and category templates and you will not need custom code and it will be much easier and 100% update proof. A child theme is not update proof.
Thank you!
