Thread:Project:Support desk/How to Customize the Main Page to show latest 5 pages added?/reply (4)

I couldn't make it look pretty and didn't want to spend the time writing my own extension to access the API so I just AJAXed it using the API feeds. It works pretty nicely though it renders about a second after the rest of the page. But if that doesn't bother you, here's the code I used.

Basically, I just had a ul that I gave the id "newestPages".

jQuery(window).load(function { jQuery.getJSON('text('scriptpath'); ?>/api.php?action=query&format=json&list=recentchanges&rctype=new&rclimit=5&rcnamespace=0', function(data) { var container = jQuery('#newestPages'); container.empty;

var results = data['query']['recentchanges']; var resultlen = results.length; for (i = 0; i < resultlen; i++) { var result = results[i]; var timestamp = result['timestamp']; var title = result["title"]; var encodedTitle = encodeURI(title); var year = timestamp.substring(2,4); var month = timestamp.substring(5,7); var day = timestamp.substring(8,10);

var formatdate = month + "." + day + "." + year; //alert(result['title']); container.append('' + formatdate + ' - text('scriptpath'); ?>/index.php/' + encodedTitle + '">' + title + ''); } }); });