【问题标题】:Get latest 10 posts from wordpress blog using Spring MVC or AngularJS使用 Spring MVC 或 AngularJS 从 wordpress 博客获取最新的 10 篇文章
【发布时间】:2015-04-28 20:22:09
【问题描述】:

我希望能够从位于如下链接的 wordpress 博客中检索前 10 条最新帖子:https://thisismyblog.wordpress.com/。我的应用程序在后端/服务器端使用 Spring MVC,并将 AngularJS 作为前端技术。

我的问题如下:有没有办法通过使用 Spring 或 AngularJS 来检索这些最新帖子?我已经尝试了此处提供的示例:http://www.fldtrace.com/display-latest-post-outside-of-wordpress-with-json-and-jquery,将示例中的链接替换为我的博客链接,但它不起作用,因为当应用程序尝试检索帖子时收到 404 Not Found 错误。我环顾四周,有些人建议使用 wordpress 提供的 RSS 提要,但我不确定我应该往哪个方向看,因为我对博客和将博客与外部应用程序链接起来还很陌生。

非常感谢任何帮助。我不限于 AngularJS,但我更喜欢 Angular 或 JavaScript/jQuery/JSON 的解决方案。

谢谢!

【问题讨论】:

  • 你确定你已经在你的wordpress实例中安装了json api插件吗?
  • 嗯,目前没有。我很难弄清楚我是否可以为我的博客做到这一点。我没有自己的域,我目前直接在 wordpress 上托管它。我会调查的。

标签: javascript jquery angularjs wordpress spring


【解决方案1】:

根据您在此小提琴中看到的代码,我设法找到了解决方案:http://jsfiddle.net/mahbub/b8Wcz/

基本上,我在 AngularJS 服务中定义如下方法,然后在 AngularJS 控制器中调用它:

AngularJS

angular.module('blog-module').factory('blogService', function($http) {

return {
    parseFeed : function(){
        return $http.jsonp('//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=JSON_CALLBACK&q=' + encodeURIComponent('https://thisismyblog.wordpress.com/feed/'));
    }
}

});

在您的控制器中,您将拥有如下内容:

blogService.parseFeed().then(function (feeds) {
        $scope.feeds = feeds.data.responseData.feed.entries;
});

这解决了我的问题。

【讨论】:

    猜你喜欢
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 2021-10-17
    相关资源
    最近更新 更多