Posted By

ryarwood on 03/17/11


Tagged

javascript wordpress jquery json


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

acousins


Read Wordpress JSON feed with jQuery


 / Published in: jQuery
 

URL: http://www.livecolonypark.com

  1. String.prototype.truncate = function(){
  2. var re = this.match(/^.{0,110}[\S]*/);
  3. var l = re[0].length;
  4. var re = re[0].replace(/\s$/,'');
  5. if(l < this.length)
  6. re = re + "...";
  7. return re;
  8. }
  9.  
  10. $(document).ready(function(){
  11. var date = new Date();
  12. $.getJSON("http://www.regishomessacramento.com/verona/news/feed/?feed=json&jsonp=?",
  13. function(data){
  14. entry = data[0];
  15.  
  16. var monthNames = [ "January", "February", "March", "April", "May", "June",
  17. "July", "August", "September", "October", "November", "December" ];
  18. var d = new Date(entry.date);
  19. var date = monthNames[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
  20. $("#newsContainerDate").html(date);
  21. var title = entry.title;
  22. $("#newsContainerTitle").html(title);
  23.  
  24. var content = entry.excerpt;
  25.  
  26. content = content.truncate();
  27.  
  28. content = content + " <a href=\"http://www.regishomessacramento.com/verona/news/\">More &gt;</a>";
  29. $("#newsContainerContent").html(content);
  30.  
  31. });
  32. });

Report this snippet  

You need to login to post a comment.