Ionic AngularJS WP Rest API 获取 WordPress 文章评论数据

整合 Ionic 和 WordPress,我们使用 WP Rest API 来进行数据操作,而 WP Rest API (v2版本)获取文章数据的路径是:

你的网站域名/wp-json/wp/v2/comments?post=1&per_page=2&page=3

这里:

post=1, 1就是文章的 id;

per_page=2,表示每页显示两条数据;

page=3,表示获取第三页的数据。
在 controller 里具体使用如下:

$http.get("你的网站域名/wp-json/wp/v2/comments?post=1&per_page=2&page=3").then(function(response){
    $scope.comments = response.data;
    console.log($scope.comments);
},function(response){
    $log.error('error', response);
});

相关文章