[WordPress] 外掛分享: WP API Menus

首頁外掛目錄 › WP API Menus
WordPress 外掛 WP API Menus 的封面圖片
2,000+
安裝啟用
★★★★★
5/5 分(8 則評價)
2039 天前
最後更新
問題解決
WordPress 3.6.0+ v1.3.2 上架:2015-01-17

內容簡介

此外掛擴充了 WordPress JSON REST API,並提供 WordPress 註冊選單的新路徑。

現在提供的新路徑如下:

/menus 所有已註冊選單的清單。
/menus/<id> 特定選單的資料。
/menu-locations 所有已註冊主題位置的清單。
/menu-locations/<location> 特定主題位置中指定選單的資料。

目前具有 menu-locations/<location> 路徑的個別選單將會返回完整的選單階層樹狀結構,並且會以正確的選單項目排序並列出每個選單項目的子項目。 menus/<id> 路徑將會輸出選單詳情及平面陣列的選單項目。每個項目的層級和排序方式都會在每個項目屬性中指示,但是此路徑不會將項目輸出為樹狀結構。

您可以使用篩選鉤子 json_menus_format_menu_item 修改每個個別選單項目及其子項目的資料佈局。

關於 WP API V2 的重要注意事項:

在 V1 中,預設路徑位於 wp-json/menus/,以此類推。

在 V2 中,預設路徑位於 wp-json/wp-api-menus/v2/(例如:wp-json/wp-api-menus/v2/menus/ 等),因為 V2 鼓勵添加前綴和版本命名空間。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.3.2) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「WP API Menus」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin extends the WordPress JSON REST API with new routes for WordPress registered menus
The new routes available will be:

/menus list of every registered menu.
/menus/ data for a specific menu.
/menu-locations list of all registered theme locations.
/menu-locations/ data for menu in specified menu in theme location.

Currently, the menu-locations/ route for individual menus will return a tree with full menu hierarchy, with correct menu item order and listing children for each menu item. The menus/ route will output menu details and a flat array of menu items. Item order or if each item has a parent will be indicated in each item attributes, but this route won’t output items as a tree.
You can alter the data arrangement of each individual menu items and children using the filter hook json_menus_format_menu_item.
An important note on WP API V2:
In V1 the routes are located by default at wp-json/menus/ etc.
In V2 the routes by default are at wp-json/wp-api-menus/v2/ (e.g. wp-json/wp-api-menus/v2/menus/, etc.) since V2 encourages prefixing and version namespacing.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon