xml -to- php -to- wordpress

2 August, 2008 – 10:51 am

brace yourself, this is going to get nerdy.

ever since i started using last.fm i’ve been frustrated at the lack of RSS feeds for user profile data, being able to pull out reports of scrobbled data is, what i would call key in using their service… so yesterday i finally got motivated and decided to have a go at fudging someone elses code… a quick google brought me to a blog post at i.ndustrio.us where the guy outlines a how-to for pretty close to what i need…

below is the code i ended up using in my side bar to display my “last.fm weekly top albums”;

<?php
$user = “_luke__”;
$url = “http://ws.audioscrobbler.com/”;
$url .=”2.0/user/$user/weeklyalbumchart.xml”;
$xml = simplexml_load_file(”$url”);

print “<table align=’centre’ border=’0′>”;
$columns=1;
$i=0;
foreach($xml->album as $album)

{
$i++;
$artist = $album->artist;
$album_name = $album->name;
$album_url = $album->url;
$album_image = $album->image->medium;

if($i==0)

print “<tr>”;

print ”
<td align=’left’>
<a href=’$album_url’>$artist - $album_name</a>
</td>
“;
if($i==$columns)
{
$i=0;
print “</tr>”;
}
}
print “</table>”;
?>

feel free to steal and fudge this as you see fit.

if i cared more, i would include a loop so that it only showed the top ten, if you implement this, let me know, cheers.





















next post: realtime scrobbling on ipod touch!

previous post: i forgot about motogp


Sorry, comments for this entry are closed at this time.