以下是的默认用法wp_nav_menu()
:
<?php
$defaults = array(
\'theme_location\' => ,
\'menu\' => ,
\'container\' => \'div\',
\'container_class\' => \'menu-{menu slug}-container\',
\'container_id\' => ,
\'menu_class\' => \'menu\',
\'menu_id\' => ,
\'echo\' => true,
\'fallback_cb\' => \'wp_page_menu\',
\'before\' => ,
\'after\' => ,
\'link_before\' => ,
\'link_after\' => ,
\'items_wrap\' => \'<ul id=\\"%1$s\\" class=\\"%2$s\\">%3$s</ul>\',
\'depth\' => 0,
\'walker\' =>
);
?>
请注意
wp_nav_menu()
是
wp_page_menu(), 默认值为:
<?php
$args = array(
\'sort_column\' => \'menu_order, post_title\',
\'menu_class\' => \'menu\',
\'include\' => \'\',
\'exclude\' => \'\',
\'echo\' => true,
\'show_home\' => false,
\'link_before\' => \'\',
\'link_after\' => \'\'
);
?>
这些应该以相同的页面集产生相同的输出。但是,如果您需要更具体的控制,您有几个选项:
在此处指定自定义回调:
\'fallback\\u cb\'=>\'mytheme\\u wp\\u nav\\u menu\\u cb\'
。。。然后,定义:
function mytheme_wp_nav_menu_cb() {
// Output whatever menu you want here
}
。。。这样您就可以覆盖
wp_page_menu()
将您的wp_nav_menu()
打电话进来has_nav_menu()
有条件的:
if ( has_nav_menu( \'my_theme_top_menu\' ) ) {
// User has applied a custom menu
// to the my_theme_top_menu location;
// output it
wp_nav_menu( array( \'theme_location\' => \'my_theme_top_menu\') );
} else {
// User has NOT applied a custom menu;
// Do something else
}
。。。在
else
声明,你可以做任何事。