【问题标题】:WP REST API posts feed doesn't show the featured imageWP REST API 帖子提要不显示特色图片
【发布时间】:2015-12-10 16:22:55
【问题描述】:

我正在尝试使用 WP REST 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 response 是:

[{"code":"json_no_route","message":"Nenhuma rota foi encontrada que corresponde com a URL e o m\u00e9todo de requisi\u00e7\u00e3o"}]

几乎所有内容都是正确的,除了未显示的特色图片。可能是什么问题?

【问题讨论】:

    标签: php json wordpress rest


    【解决方案1】:

    Wordpress 新更新(4.4)在核心中添加其余 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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      相关资源
      最近更新 更多