2016-02-27 49 views
1

我試圖查看是否可以使用Javascript查詢wordpress API以獲取網站菜單中的所有項目。使用javascript獲取WordPress網站中的菜單項

我可以看到有一個帖子here關於如何在php中這樣做,但我不知道如何將它翻譯爲JavaScript,因爲它似乎是使用內部WordPress的PHP API。

有一個great library here,我可以看到,下面的代碼,我可以查詢網站:

var site = Site('<id>', WPCOM); 
site.get(function(err, info){ 
    // `info` data object 
}); 

但我不知道如何查詢菜單項或如果這是在所有可能的?

任何幫助,將不勝感激。

回答

0

我沒有代表將此鏈接置評論中。我沒有用它,不知道它是否會做你需要什麼,但這個怎麼樣頁:https://wordpress.org/plugins/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/<id> data for a specific menu. 
     /menu-locations list of all registered theme locations. 
     /menu-locations/<location> data for menu in specified menu in theme location. 

我也在wordpress.stackexchange上發現了這個類似帖子:https://wordpress.stackexchange.com/questions/209381/get-wp-navigation-menu-from-rest-api-v2。它最終指向相同的'wp-api-menus /'鏈接。

+0

謝謝。這就是我所追求的。 –

相關問題