默认的回退菜单是使用wp_page_menu() 功能,如果要自定义,则需要创建自己的回退功能:
function my_fallback_menu(){
$args =array(\'whatever\');
wp_page_menu($args);
}
然后在wp\\U nav\\U菜单调用中调用该函数作为回退:
wp_nav_menu(array(
\'theme_location\' => \'mainnav\',
\'container\' => \'nav\',
\'container_id\' => \'mainnav\',
\'container_class\' => \'clearfix\',
\'depth\' => 4,
\'fallback_cb\' => \'my_fallback_menu\'
));
要检查菜单是否存在,可以使用
has_nav_menu()
功能:
if (has_nav_menu( \'mainnav\' )){
//display the menu
}else{
//no menu yet do something else
}
为了进一步简化操作,您可以调用菜单并将回退设置为false:
wp_nav_menu(array(
\'theme_location\' => \'mainnav\',
\'container\' => \'nav\',
\'container_id\' => \'mainnav\',
\'container_class\' => \'clearfix\',
\'depth\' => 4,
\'fallback_cb\' => false
));