如何在阵列中获取菜单?
使用wp_nav_menu ( );
,我将获得包含HTML的列表,但我不想要HTML标记。我只想要数据。
我找到了这个,但这行是什么 - $menu_name = 'custom_menu_slug';
?
$menu_name = 'custom_menu_slug'; // Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu)
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
}
}
有什么想法吗?