The following code takes data from an XML file and outputs each item in div="item"
I've converted the date so that instead of the full date you get it in YYYYMMDD (e.g 20131216)
var date = new Date( $item.find('pubDate').text() );
var yyyymmdd = date.getFullYear() +''+ (date.getMonth()+1) +''+ date.getDate();
array += '<p>' + yyyymmdd + '</p>';
1. But now I need to sort this data and store it in a sub-array, so that only the last 30 days are stored in the sub-array.
Full script:
jQuery(function(){
$.ajax({
url: 'http://www.sagittarius-digital.com/news.rss',
dataType: 'xml'
}).done(function(xml){
var items = $(xml).find('item').map(function(){
var $item = $(this);
var array = '<div class="item">';
array += '<a href="' + $item.find('link').text() + '">';
array += '<h2>' + $item.find('title').text() + '</h2>';
array += '<p>' + $item.find('description').text() + '</p>';
var date = new Date( $item.find('pubDate').text() );
var yyyymmdd = date.getFullYear() +''+ (date.getMonth()+1) +''+ date.getDate();
array += '<p>' + yyyymmdd + '</p>';
array += '<p>Category: ' + $item.find('category').text() + '</p>';
array += '</a>';
array += '</div>';
return array;
}).get();
$('div.item').append(items.join(' '));
}).fail(function(){
console.log('error', arguments)
})
})
2. And then I need to randomise the output of that sub-array so that the last X items (from last 30 days) output in a random order. This will ensure the data is "recent", but doesn't show in perfect chrono order.
Does anyone have any ideas?