您尚未添加fallback_cb
参数数组的键。您还需要添加theme_location
密钥:
php start $menu = wp_nav_menu(
array(
\'menu_class\' => \'reset sf-menu\',
\'container_id\'=>\'nav\',
\'echo\'=>0,
\'fallback_cb\' => \'mytheme_fallback_function\' // ADD ME!!!
\'theme_location\' => `location_name` // ADD ME, AS DEFINED IN register_nav_menu()
)
);
$menu = str_replace("\\n", "", $menu);
$menu = str_replace("\\r", "", $menu);
$menu = str_replace("\\t", "", $menu);
echo $menu;
php end
或者,您可以将代码包装在
if ( has_nav_menu( \'location_name\' ) )
有条件的:
if ( has_nav_menu( \'location_name\' ) ) {
echo $menu;
} else {
// Do something else, like wp_list_pages() or wp_page_menu()
}