parse wordpress RSS feed using ajax / jquery


/ Published in: JavaScript
Save to your folder(s)

* Set your local path to the wordpress install, in my case was: "/blog/feed"
* Edit the var contain = make it set to the selector, in my case I'm populated a list tag <ul></ul>.
* Edit the var limit = 5; Set the amount of blog posts you want to display.


Copy this code and paste it in your HTML
  1. $.ajax({
  2. type: "GET",
  3. url: "/blog/feed",
  4. dataType: "xml",
  5. success: function(xml) {
  6.  
  7. var contain = $("div.panel ul");
  8. var limit = 5;
  9.  
  10. $(xml).find('item').each(function(index){
  11. if( index < limit ){
  12. var title = $(this).find('title').text();
  13. var url = $(this).find('link').text();
  14. var pubDate = $(this).find('pubDate').text();
  15. $('<li></li>').html('<a href="'+url+'">'+title+'</a>').appendTo(contain);
  16. return;
  17. }
  18.  
  19. });//end each
  20. }
  21. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.