Simple Last.fm
I’ve never really been happy with any of the ‘now playing’-style plugins for Last.fm. So this weekend, I threw something together myself; something easier than a plugin. Now, I’ll show you how to get a simple, auto-refresh album cover in the sidebar, just like the one on this site. All you need is a small .js file (tiny!) and a standard WordPress text widget. Let’s get started.
Right-click and download this -> lastfm.js file and put it somewhere on your webserver. This isn’t a plugin, so it doesn’t need to live anywhere special. Open the file with your favorite editor and enter a Last.fm user name, api key, and a path for a placeholder (in case the API doesn’t return an image).
Next, log in to your WordPress dashboard, select Widgets, and drag over a new standard text widget. Paste this block into the widget content area, update the server path, and save.
1 2 3 4 |
<script src='http://your.path.to/lastfm.js'></script> <div id='lastfm'></div> |
That’s it! Fire up your music player and reload your site. Every few minutes a new cover should load with a nice fade-in. The Last.fm API doesn’t provide a way to update when a new track starts, but you can adjust the refresh rate in lastfm.js
to your liking. Every 3 or 4 minutes works pretty well.