Skip to content

Instantly share code, notes, and snippets.

@kurai021
Last active March 22, 2017 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurai021/64da81d881da0075c6a8118231d5815e to your computer and use it in GitHub Desktop.
Save kurai021/64da81d881da0075c6a8118231d5815e to your computer and use it in GitHub Desktop.
rss parser para wordpress
$(document).ready(function() {
//feed to parse
var feed = "https://cors-anywhere.herokuapp.com/https://comunicacionconvalor.com/feed/";
var html = "";
$.ajax(feed, {
accepts:{
xml:"application/rss+xml"
},
dataType:"xml",
success:function(data) {
//Credit: http://stackoverflow.com/questions/10943544/how-to-parse-an-rss-feed-using-javascript
var i = 0;
$(data).find("item").each(function () {
if (i < 4){
var el = $(this);
var description = el.find("description").text();
var slice = description.slice(0,100) + "...";
var title = el.find("title").eq(0).text();
var categories = "";
el.find("category").each(function() {
categories += " " + $(this).text();
});
var tags = categories;
var link = el.find("link").text();
var thumbnail;
if($.browser.webkit){
thumbnail = el.find('thumbnail').attr('url');
}
if($.browser.mozilla) {
thumbnail = el.find('media\\:thumbnail').attr('url');
}
if(thumbnail == undefined){
thumbnail = "assets/images/logo.png"; //cualquier imagen para fallback
}
else {
thumbnail = thumbnail + "?w=440&h=297&crop=1";
}
var post = "<div class='ipost col-sm-6 bottommargin clearfix'>"+
"<div class='row'>"+
"<div class='col-md-6'>"+
"<div class='entry-image nobottommargin'>"+
"<a href='"+ link +"' target='_blank'>"+
"<img src='"+ thumbnail +"' alt='sl-studio-img' />"+
"</a>"+
"</div>"+
"</div>"+
"<div class='col-md-6' style='margin-top: 5px;'>"+
"<span class='before-heading' style='font-style: normal;'>"+ tags +"</span>"+
"<div class='entry-title'>"+
"<h3 class=''><a href='"+ link +"' target='_blank'>"+ title +"</a></h3>"+
"</div>"+
"<div class='entry-content'>"+
"<p>"+ slice +"</p>"+
"<a href='"+ link +"' target='_blank' class='more-link'>Continuar leyendo <i class='icon-angle-right'></i></a>"+
"</div>"+
"</div>"+
"</div>"+
"</div>";
html = html + post;
i++
}
});
document.getElementById("blog-sec").innerHTML = html;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment