Hey pimhd,
probably this user defined tag I quickly made can give you a start:
Code: Select all
$lastfmfeed = simplexml_load_file($params[url]);
foreach ($lastfmfeed ->topartists->artist as $artist)
{
$output .= $artist->name.'<br />'."\n";
$output .= $artist->playcount.'<br />'."\n";
$output .= $artist->url.'<br />'."\n";
$output .= $artist->name.'<br />'."\n";
$output .= '<img src="'.$artist->image[0].'" />'."\n";
$output .= '<img src="'.$artist->image[1].'" />'."\n";
$output .= '<img src="'.$artist->image[2].'" />'."\n";
$output .= '<hr />';
}
echo $output;
Save this as a user tag with the name lastfmfeed and call the tag from your content or template like in the example below:
Code: Select all
{lastfmfeed url="http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=rj&api_key=b25b959554ed76058ac220b7b2e0a026"}
However, to use this, you need to have
php5 and
allow_url_fopen = On in your php.ini to allow simplexml to access external urls.
The script gets the xml from the url, looks for the node "topartists" in the xml document, and then walks trough the list of nodes with the name "artist". Afterwards it prints the value of selected variables for each artist entry.
For the code above I used a sample API 2.0 feed from last.fm (I think yours above was 1.0). But anyway, I guess the code can give you some directions and you can quickly alter it to match your needs.
If you want to access a specific element (e.g. the name of the newest artist in the list), you do not need to cycle through the elements. This should give you a start:
Code: Select all
$lastfmfeed = simplexml_load_file($params[url]);
echo $lastfmfeed ->topartists->artist[0]->name;
Let me know how it turned out for you.
Best
Nils