fetching wordpress posts using google feeds api

Building my new website (again) and decided to feed one of my existing blogs to it, using javascript to pull in the content after the main page has loaded, usual style…

i decided to use the google feeds api for fetching wordpress posts.

here’s my html:

[code]
<div id="feeds">
<h3>From Tizards Briefcase</h3>
<div class="feedBox" data-url="tizardsbriefcase.com/feed">
…fetching data from tizards briefcase…
</div>
</div><!– // #feeds –>
[/code]

(i plan of having more than one .feedBox of course :))

and the javascript:

[code]
// feeds
$(‘#feeds .feedBox’).each(function()
{
var feedBox = $(this);
var feed = ‘http://’ + feedBox.data(‘url’);
$.ajax(
{
url: ‘http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=2&callback=?&q=’ + encodeURIComponent(feed),
dataType: ‘json’,
success: function(data)
{
var fd = data.responseData.feed;
console.log(‘title: ‘ + fd.title);
console.log(‘link: ‘ + fd.link);

var out = ”;
$(fd.entries).each(function()
{
entry = $(this)[0];
console.log(entry);
out += ‘<h4>’ + entry.title + ‘</h4>’;
out += ‘<p>’ + entry.contentSnippet + ‘ <a href="’ + entry.link + ‘">read more</a></p>’;
});
feedBox.html(out);
}
});
});
[/code]

excuse the console.logs, i’ve only just written it and still building my pages as i type this.

each entry has these properties:

author
categories
content
contentSnippet
link
publishedDate
title




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *