Last loved track on last.fm

WordPresstuttorial – Adding this wordpress code snippet to your theme will display your most recent loved track from last.fm. Make sure you change YOURUSERNAME text within the RSS url to your last.fm username.

 

 

<?php
$rss = fetch_feed('http://ws.audioscrobbler.com/2.0/user/YOURUSERNAME/lovedtracks.rss');
if (!is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity(1);
$rss_items = $rss->get_items(0, $maxitems);
endif; ?>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
foreach ( $rss_items as $item ) : ?>
<a href='<?php echo $item->get_permalink(); ?>' target='_blank'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo $item->get_title(); ?></a>
<?php endforeach; ?>

Leave a comment