如何在 Wordpress 中获取菜单项? [英] How to Get Menu Items In Wordpress?

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

问题描述

我想获取我的 wp 主菜单的项目.我尝试了一些代码,但所有代码都只返回空白页.我不知道我必须使用哪种方法,也不知道需要在我的页面中包含任何其他页面?

有没有办法直接从数据库中获取菜单项而不使用 wp 方法和函数?我现在无法理解 wp 的表结构.所以我不知道表之间的关系.

谢谢.

解决方案

你可以试试这个

$menu_name = 'sidebar-menu';//菜单栏$locations = get_nav_menu_locations();$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );echo "

";打印_r($menuitems);echo "</pre>";

你会得到你的菜单对象

参考:http://wiki.workassis.com/wordpress-get-menu-数组/

I want to get items of my wp primary menu. I tried some code but all of them are returns only blank page. I don't know which method I must use and don't know need include any other page to my page?

And Is there any way to get menu items from database directly without using wp methods and functions? I couldn't understand table structure of wp for now. So I don't know relationships between tables exactly.

Thanks.

解决方案

You can try this

$menu_name = 'sidebar-menu'; //menu slug
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );

echo "<pre>";
print_r($menuitems);
echo "</pre>";

You will get your menu Object

refer : http://wiki.workassis.com/wordpress-get-menu-array/

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

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