Parse RSS modification

50 views Asked by At

Sorry to ask but need some help. I'm using the below script shown to parse an RSS feed of blog entries. In this example, I'm using "Mashable" feed as the feed source to demonstrate.

Issue:

The blog entry images and links appear correctly. But the problem is, I'd like to also include the blog entry titles for output as well, and not sure how to write it.

Can anyone take a look and offer a suggestion as to how I might include the entry title (+ link) in the below script if possible?

I'd be grateful for any suggestions or help. Thank you.

Script:

$parseRSS({
url: "http://feeds.mashable.com/Mashable?format=xml",
count: 16,
callback: function(posts) {
    for(var i = 0; i < posts.length; i++) {
        var img = posts[i].content.split('src="')[1].split('"')[0];
        var link = posts[i].link;
        document.body.innerHTML += '<a href="' + link + '"><img src="' + img + '"></a>';
    }
} });
1

There are 1 answers

2
janih On BEST ANSWER

posts array contains also titles, so you just need to append them to the document body:

var title = posts[i].title;
var link = posts[i].link;
document.body.innerHTML += '<h1>' + title + '</h1>';
document.body.innerHTML += '<p><a href="' + link + '">link</a></p>';
document.body.innerHTML += '<a href="' + link + '"><img src="' + img + '"></a><br>';

codepen