WordPress上JSON Content Importer的使用
範例網址|https://tourevent.tw/wp-content/plugins/json-content-importer/json/gutenbergblockexample1.json
資料格式
{ "level1": { "start": "Very good, this is the value of 'start', right out of the JSON-data", "level2": [{ "key" : "This is the first value of key in the 'level1'-array", "data": { "id": 11111, "type": "aaaa" } }, { "key" : "This is the second value of key in the 'level1'-array", "data": { "id": 222, "type": "bbbb" } }, { "key" : "This is the third value of key in the 'level1'-array", "data": { "id": 33333333, "type": "aaaa" } }, { "key" : "This is the fourth value of key in the 'level1'-array", "data": { "id": 4444, "type": "aaaa" } }] } }
JSON Content Importer的shortcode
[JCI_SHORTCODE url="https://tourevent.tw/wp-content/plugins/json-content-importer/json/gutenbergblockexample1.json" debugmode="0" urlgettimeout="10" basenode="level1"] {start}<br>{subloop-array:level2:-1}{level2.key} <br> {subloop:level2.data:-1}id: {level2.data.id} <br> {/subloop:level2.data}{/subloop-array:level2} [/JCI_SHORTCODE]
上面的JCI_SHORTCODE為「jsoncontentimporter」
拆解結果
EMPTY api-answer: No JSON received - is the API down? Check the URL you use in the shortcode!- debugmode:2, shows some debug infos;10, all available debug infos.
- basenode:starting point of datasets, the base-node in the JSON-Feed where the data is
Template(以上面的範例來解說)
- {start}:提取basenode下的start標籤內容
- 透過{subloop-array}與{subloop}來迴圈取得資料數值
- {subloop-array:標籤名稱:數量}:在「[ ]」中,迴圈取值的標籤名稱以及要提取的數值個數,如果數量為「-1」,代表提取全部數值
- {subloop:標籤名稱:數量}:在「{ }」中,迴圈取值的標籤名稱以及要提取的數值個數,如果數量為「-1」,代表提取全部數值
官方文件連結|Documentation of JSON Content Importer Plugin – WordPress-Plugin JSON Content Importer