我是WP Web api的新手。
我想从我的网站的页面上的远程站点呈现页面的内容:
http://www.my-url/wp-json/wp/v2/pages/34/
如何在我自己的网站上解析,渲染和嵌入页面上的内容?我最终需要做什么?有javascript示例吗?或者我需要在PHP中执行此操作?
在此先感谢您的帮助....
使用jQuery .ajax函数实现了所需的工作。
在我希望呈现远程站点内容的页面上,我使用以下内容:
<script>
$( document ).ready(function() {
$.ajax({
url: 'http://www.my-url/wp-json/wp/v2/pages/34/',
error: function() {
$('#info').html('<p>An error has occurred</p>');
},
dataType: 'json',
async: false,
type: 'GET',
success: function(data) {
var theContent = data;
document.getElementById("remote-content").innerHTML = theContent.content.rendered;
}
});
});
</script>
<span id="remote-content"></span>