我正在尝试使用WPRESTneneneba API v2插件将wordpress博客中的一些帖子提供给我的PHP网站。我的代码是:
<?php
$json = file_get_contents('http://noticias.uscs.edu.br/wp-json/wp/v2/posts?filter[posts_per_page]=6&filter[orderby]=date');
// Convert the JSON to an array of posts
$posts = json_decode($json);
foreach ($posts as $p) {
echo '<p><a href="'.$p->link.'">'.$p->title->rendered.'</a><p>';
// Output the featured image (if there is one)
echo $p->featured_image ? '<img src="' . $p->featured_image->guid . '">' : '';
}
?>
$json
响应为:
[{"code":"json_no_route","message":"Nenhuma rota foi encontrada que corresponde com a URL e o m'u00e9todo de requisi'u00e7'u00e3o"}]
几乎所有的东西都是对的,更不用说没有显示的特色图片了。可能是什么问题?
Wordpress new update(4.4)在核心中添加了rest api:https://make.wordpress.org/core/2015/10/28/rest-api-welcome-the-infrastructure-to-core/
您可以使用Posts API获取拇指邮件http://v2.wp-api.org/reference/posts/