Home / social / Last loved track on last.fm
  • How to Last loved track on last.fm


    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.

    ( click code to copy )

    wordpress snippet : 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>';
        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; ?>

    ( WordPress codex functions, hooks, in this snippet. )

    get_permalink, fetch_feed, _e, is_wp_error, wp,