wp_get_nav_menu_items()获取在后台自定义的导航菜单项

目录

描述

Returns the items from a navigation menu created in the AppearanceMenus panel.

Given a menu name, id or slug, the function returns the menu items from that navigation menu. The menu items returned are in fact the actual nav_menu_item type posts which contain references to the normal posts/pages they are associated with.

wp_get_nav_menu_items() 描述

用法

 <?php $items wp_get_nav_menu_items$menu$args ); ?> 

Default Usage

<?php $args = array(
        
'order'                  => 'ASC',
        
'orderby'                => 'menu_order',
        
'post_type'              => 'nav_menu_item',
        
'post_status'            => 'publish',
        
'output'                 => ARRAY_A,
        
'output_key'             => 'menu_order',
        
'nopaging'               => true,
        
'update_post_term_cache' => false ); ?>

wp_get_nav_menu_items() 用法

参数

$menu

(string) (必填) Menu 'id','name' or 'slug'

默认值: None

The nav menu location is not a valid argument. For example : if you registered nav menu using the function register_nav_menus() and pass an argument like array( 'menu_1' => __( 'Menu 1', 'textdomain')) to the function, the location slug 'menu_1' is not a valid argument. Please check up the example code below to see how it work.

$args

(array) (可选) Optional arguments

默认值: None

wp_get_nav_menu_items() 参数

返回值

Indexed array of augmented WP_Post objects (empty if the menu contains no items) or bool false.

The following is a sample of object returned. This is a child menu item, a category link, with custom Navigation Label, Title Attribute, CSS Classes, Link Relationship and Description:

wp_get_nav_menu_items() 返回值

示例

Building simple menu list

wp_get_nav_menu_items() 示例

相关