Skip to content

Instantly share code, notes, and snippets.

@magician11
Last active August 29, 2015 14:22
Show Gist options
  • Save magician11/829370d6c02662b159bf to your computer and use it in GitHub Desktop.
Save magician11/829370d6c02662b159bf to your computer and use it in GitHub Desktop.
An AngularJS factory to fetch WordPress feeds
(function() {
"use strict";
var agApp = angular.module('agApp');
agApp.factory('WordPressFeed', function($http) {
function getLatestPosts(wpWebsite, numPosts, callback) {
var feedUrl = wpWebsite + '/feed/';
// docs for this API: https://developers.google.com/feed/v1/jsondevguide
$http.jsonp('http://ajax.googleapis.com/ajax/services/feed/load', {
params: {
v: '1.0', q: feedUrl, callback:'JSON_CALLBACK', num: numPosts
}
})
.success(function(response) {
callback(response.responseData.feed.entries);
});
}
return {
getLatestPosts: getLatestPosts
};
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment