The Pug Automatic

Scrobbler (Last.fm) sidebar module

Written August 20, 2006. Tagged PHP, WordPress.

I recently switched this blog to the K2 WordPress theme. By the time you read this, I might be using something else – the blog is new and its appearance very much in flux.

K2 supports sidebar modules, similar to sidebar widgets.

I created such a sidebar module for use with the Scrobbler plug-in, which displays Last.fm data in your blog.

Though there's nothing non-obvious about the code, it still might save someone else some work.

The module displays the Last.fm favicon to the right of the header, similar to the RSS icon in some other modules. It achieves this by leveraging the feedlink CSS class. If you're anal about semantic HTML, you might want to rework this.

Watch it in action (at the time of writing, at least) at my "About" page.

This goes into a file like wp-content/themes/k2/modules/lastfm.php (download):

<?php

function lastfm_sidebar_module($args) {
global $scrobbler_user;
extract($args);

if ( function_exists('get_scrobbler') ) {
echo $before_module . $before_title . $title . $after_title;
?>

<span class="metalink"><a href="http://www.last.fm/user/<?php echo $scrobbler_user; ?>" class="feedlink" title="My Last.fm profile"><img src="http://static.last.fm/matt/favicon.ico" alt="Last.fm" /></a></span>

<?php
get_scrobbler();
echo $after_module;
}
}

register_sidebar_module('Last.fm module', 'lastfm_sidebar_module', 'sb-lastfm');

?>