数组中的菜单项 [英] menu item in array

查看:88
本文介绍了数组中的菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将菜单项(深度= 1)放入数组?

How do I get the menu items (depth = 1) into an array?

wp_nav_menu输出带有ul和li元素的格式化列表. wp_list_pages还会输出带有ul和li的格式化列表.

wp_nav_menu outputs a formatted list with both ul and li elements. wp_list_pages also outputs a formatted list with both ul and li.

我只想将深度为一的菜单项(带标签的标签)放入一个数组中.

I just want to get the menu items (striped of tags) of depth one into an array.

我如何做到这一点?

推荐答案

我认为这会为您提供帮助: wp获取导航菜单项

I think this will helps you: wp get nav menu items

    $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;
    }
    }

这篇关于数组中的菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆