Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.         This snippet requires the WordPress JSON feed plugin
  3.         Found here: http://wordpress.org/extend/plugins/json-feed/
  4.         The plugin provides a new WordPress feed option
  5.  
  6.     Also see my ColdFusion Proxy to avoid Cross-Site Scripting Pastebin:
  7.     http://pastebin.com/XTBmUHP0
  8. */
  9. $(document).ready(function () {
  10.     // Cache the "result" div
  11.     var blogContent = $('#blogcontent');
  12.    
  13.     // Get the feed via AJAX, in this case, using jQuery 1.7.1
  14.     $.ajax({
  15.         type:   'get',
  16.         // url must be on the same domain as the script
  17.         url:    'http://path.to/feed/?feed=json',
  18.         dataType:   'json',
  19.         beforeSend: function() {
  20.             // show an animated gif to indicate something happening
  21.             blogContent.html('<p><img src="/i/img/loading.gif" width="16" height="16" alt="Loading &#8230;" /> Loading &#8230;</p>');
  22.         },
  23.         error: function(data, status, error) {
  24.             // ajax request failed, display an error
  25.             blogContent.html('<p>Blog Feed is not available.</p>');
  26.             console.log(data); // remove for production
  27.             console.log(status); // remove for production
  28.             console.log(error); // remove for production
  29.         },
  30.         success: function(data) {
  31.             // clear animated gif
  32.             blogContent.html('');
  33.             var blogItems = []; // create empty array
  34.             $.each(data, function(i, item) {
  35.                 // only return the first 6 items from the feed
  36.                 //change to the number you want to display;
  37.                 if (i === 6) return false;
  38.                 // add the current item to the blogItems array
  39.                 blogItems.push('<p>\r\n\t<a href="' + item.permalink + '">' + item.title +'</a>\r\n</p>');
  40.             });
  41.             // add array of items to the "result" div
  42.             blogContent.append(blogItems.join(''));
  43.             console.log(data); // remove for production
  44.         }
  45.     });
  46. });