想利用WP做後台,做一個Hybird應用。我沒做過HybirdApp,想利用JqueryMobile+Phonegap或Appcan來完成
剛裝了一個名為JSON API的外掛程式,的確可以匯出JSON資料,不過好像還是有些問題的,例如複雜的Tags Post就沒有資料,剛度娘發現說是WP4.0後,就已經加入了JSON支援了,發現關於Wordpress JSON的外掛程式和文章還不少,一頭霧水
搭建一個Wordpress JSON api有什麼正確的方法嗎?
回複內容:
想利用WP做後台,做一個Hybird應用。我沒做過HybirdApp,想利用JqueryMobile+Phonegap或Appcan來完成
剛裝了一個名為JSON API的外掛程式,的確可以匯出JSON資料,不過好像還是有些問題的,例如複雜的Tags Post就沒有資料,剛度娘發現說是WP4.0後,就已經加入了JSON支援了,發現關於Wordpress JSON的外掛程式和文章還不少,一頭霧水
搭建一個Wordpress JSON api有什麼正確的方法嗎?
感覺題主繞了個大圈,見以下連結中的描述目標、而不是過程
https://github.com/seajs/seajs/issues/545
按現有的目標,看不懂為什麼要用WP,想要返回JSON資料(並且是支援WP的環境)直接上PHP指令碼就好了
通過echo json_encode(data)即可
按題主評論更新:
謝謝回答,我主要是想敘述一下我其中遇到的問題,其實就是想問怎麼樣做最好,另外我用WP是因為想基於我現在站裡的資訊來調用~
既然使用WP的目的是基於WP站內資訊進行調用,思路就比較明確:
- 如何匯出WP站內資訊(基於JSON)
- 如何在Hybrid APP中使用這些資訊
題主現在的問題描述並不涉及Hybrid APP的問題
fan qiang 用 Google 搜尋 wordpress json api
第一個結果是:https://wordpress.org/plugins/json-api/
裡面有完整的JSON API安裝及使用教程,
1.3. Responses
The standard response format for JSON API is (as you may have guessed) JSON.
Here is an example response from http://localhost/wordpress/?json=1 called on a default WordPress installation (formatted for readability):
{ "status": "ok", "count": 1, "count_total": 1, "pages": 1, "posts": [ { "id": 1, "type": "post", "slug": "hello-world", "url": "http:\/\/localhost\/wordpress\/?p=1", "title": "Hello world!", "title_plain": "Hello world!", "content": "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!<\/p>\n", "excerpt": "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!\n", "date": "2009-11-11 12:50:19", "modified": "2009-11-11 12:50:19", "categories": [], "tags": [], "author": { "id": 1, "slug": "admin", "name": "admin", "first_name": "", "last_name": "", "nickname": "", "url": "", "description": "" }, "comments": [ { "id": 1, "name": "Mr WordPress", "url": "http:\/\/wordpress.org\/", "date": "2009-11-11 12:50:19", "content": "
Hi, this is a comment.
To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.<\/p>\n", "parent": 0 } ], "comment_count": 1, "comment_status": "open" } ]}
從返回資料來看,是有tags及post的,可以滿足題主的需求