Wordpress如何搭建一個API環境?

來源:互聯網
上載者:User
想利用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站內資訊進行調用,思路就比較明確:

  1. 如何匯出WP站內資訊(基於JSON)
  2. 如何在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的,可以滿足題主的需求

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.