<\/span><\/h2>\n\n\n\nadd_filter( 'wp_nav_menu_objects', 'uzi_wp_nav_menu_objects' );\nfunction uzi_wp_nav_menu_objects( $sorted_menu_items )\n{\n foreach ( $sorted_menu_items as $menu_item ) {\n if ( $menu_item->current ) {\n $_SESSION['uzi_current_menu'] = $menu_item;\n break;\n }\n }\n return $sorted_menu_items;\n}<\/pre>\n\n\n\n\u5168\u5c40\u53d8\u91cf$_SESSION['uzi_current_menu']<\/code>\u8bb0\u5f55\u4e86\u5f53\u524d\u83dc\u5355\u7684current menu item\u7684\u6807\u9898\u3002<\/p>\n\n\n\n\u4e00\u4e9b\u6bd4\u8f83\u6709\u7528\u7684\u4fe1\u606f\u5982\u4e0b<\/p>\n\n\n\n
$menu_item->ID - Menu ID\n$menu_item->title - \u8be5\u83dc\u5355\u9879\u540d\u79f0\n$menu_item->post_title - Post Title,\u4e0d\u4e00\u5b9a\u548c\u83dc\u5355\u9879\u540d\u79f0\u76f8\u540c\n$menu_item->url - \u56fa\u5b9a\u94fe\u63a5\n$menu_item->object_id - post ID\n$menu_item->post_parent - Post Parent\uff08\u4f8b\u5982page\u7684parent page\uff09\n$menu_item->menu_item_parent - \u6307\u5728\u8be5\u83dc\u5355\u4e2d\u7684\u5c42\u7ea7\u5173\u7cfb<\/pre>\n\n\n\n<\/span>\u8f93\u51famain-nav\u83dc\u5355\u4e2d\uff0c\u5f53\u524d\u9875\u9762\u6240\u5728\u83dc\u5355\u7684\u5b50\u83dc\u5355<\/span><\/h2>\n\n\n\n$locations = get_nav_menu_locations();\n$menu = wp_get_nav_menu_object($locations['main-nav']); \/\/ primary' is our nav menu's name\n$menu_items = wp_get_nav_menu_items($menu->term_id);\n\/\/ var_dump($menu,$_SESSION['uzi_current_menu']->ID,$menu_items);\nif (!empty($menu_items)) {\n echo '<ul>';\n foreach ($menu_items as $menu_item) {\n if($menu_item->menu_item_parent == $_SESSION['uzi_current_menu']->ID\n || $menu_item->menu_item_parent == $_SESSION['uzi_current_menu']->\t\t\tif ($menu_item->menu_item_parent == $_SESSION['uzi_current_menu']->ID\n\t\t\t\t|| ($menu_item->menu_item_parent == $_SESSION['uzi_current_menu']->menu_item_parent && 0 != $menu_item->menu_item_parent)\n\t\t\t) {\n\t\t\t\t\/\/\u5224\u65ad\u5f53\u524d\u9875\u9762\u662f\u8be5\u83dc\u5355\u9879\u7684\u5b50\u9879\n\t\t\t\tif (is_page($menu_item->object_id) || is_category($menu_item->object_id)) {\n\t\t\t\t\techo '<li class=\"current-menu-item\">';\n\t\t\t\t} else {\n\t\t\t\t\techo '<li>';\n\t\t\t\t}\n\t\t\t\techo '<a href=\"' . $menu_item->url . '\">' . $menu_item->title . '<\/a>';\n\t\t\t\techo '<\/li>';\n\t\t\t} \n }\n echo '<\/ul>';\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u9047\u5230\u4e00\u4e2a\u95ee\u9898\uff0c\u8981\u663e\u793a\u5f53\u524d\u9875\u9762\u7684\u9762\u5305\u5c51\u5bfc\u822a\uff0c\u53ea\u662f\u8fd9\u4e2a\u9762\u5305\u5c51\u8def\u5f84\u53cd\u5e94\u7684\u4e0d\u662f\u9875\u9762\u81ea\u8eab\u7684\u5c42\u7ea7\u5173\u7cfb\uff0c\u800c\u662f\u8be5\u9875\u9762\u5728\u83dc\u5355\u5bfc\u822a […]<\/p>\n","protected":false},"author":1,"featured_media":43051,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[33,333,265],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/47842"}],"collection":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/comments?post=47842"}],"version-history":[{"count":0,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/47842\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media\/43051"}],"wp:attachment":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media?parent=47842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/categories?post=47842"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/tags?post=47842"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}