我试图在我的PHP网站上显示另一个Wordpress网站上的一些帖子,该网站使用安装的WPRESTneneneba API插件。我正试图用下面的代码做到这一点,但什么也没发生:
<?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>Title: ' . $p->title . '</p>';
echo '<p>Date: ' . date('F jS', strtotime($p->date)) . '</p>';
// Output the featured image (if there is one)
echo $p->featured_image ? '<img src="' . $p->featured_image->guid . '">' : '';
}
?>
有什么意见吗?提前谢谢。
在这一行上,echo '<p>Title: ' . $p->title . '</p>';
$p->标题是一个对象,所以你必须像这样做来修复它:
echo '<p>Title: ' . $p->title->rendered . '</p>';