fmTuner: A Last.fm Plugin for WordPress

fmTuner BannerThe result of the “Tunes” sidebar element on the Command-Tab homepage, fmTuner is a small WordPress plugin for retrieving song details from your Last.fm profile and publishing them anywhere in your WordPress theme. It provides options for choosing among your Recent, Loved, or Top tracks, as well as tools to adjust the update frequency and appearance:

Settings - fmTuner: A Last.fm Plugin for WordPress

Of particular note is the customizable Display Format option. Using simple tags like [::artist::] and [::image::] intermixed with regular HTML, you can tweak your Last.fm tracks exactly how you like, or however your WordPress theme requires. You have full control!

Download fmTuner Now

Requirements

  • WordPress 2.5 or later.
  • PHP 5 or later (fmTuner uses PHP 5’s SimpleXML for decoding Last.fm data).
  • Basic knowledge of PHP, HTML, and WordPress.

Installation

  • Upload “fmtuner.php” to a directory inside “/wp-content/plugins/” directory. For example: “/wp-content/plugins/fmtuner/fmtuner.php”
  • Ensure “/wp-content/plugins/fmtuner/” is writable by your webserver (chmod 755 fmtuner).
  • Activate the plugin through the “Plugins” menu in WordPress.
  • Set up options in the “Settings” menu in WordPress.
  • Place “if(function_exists(’fmtuner’)) { fmtuner(); }” in your templates, between PHP tags.

Release History

  • fmTuner 1.0.4
    Released on Dec. 14, 2008
    Made minor tweaks for fmTuner Settings page under WordPress 2.7.
  • fmTuner 1.0.3
    Released on Nov. 15, 2008
    By request, a [::number::] fmTuner tag has been added, which emits a sequential number for each track (starting at 1). This is particularly useful for CSS and JavaScript display purposes.
  • fmTuner 1.0.2
    Released on Oct. 5, 2008
    Added a cURL-based alternative to file_get_contents to hopefully resolve “URL file-access is disabled” issues. If allow_url_fopen is disabled in the php.ini, cURL will be used to fetch the Last.fm feed instead.
  • fmTuner 1.0.1
    Released on Sept. 9, 2008
    Added better failure checking and informational messages, removed development code, and updated instructions.
  • fmTuner 1.0
    Released on Sept. 6, 2008
    Initial release.

Released under the MIT License. Do with fmTuner whatever you wish. Mod it, mash it, hack it. Make it yours.

41 Responses to “fmTuner: A Last.fm Plugin for WordPress”

  1. [...] A Last.fm Plugin for WordPress No Comments Sep 06 at 9:51 pm by Rogie fmTuner is a small WordPress plugin for retrieving song details from your Last.fm profile and publishing [...]

  2. it would be much cooler if it would be made as a standalone application

  3. @neondragon: Do you mean a standalone php script?

  4. hi. Thanks for plugin

    perfect.

    Regards

  5. Can you please advice what should I check if fmtuner() function gives zero output?

    I have cache xml file downloaded correctly.

  6. @Mad Cat: How is your Display Format set up? Still the default? Also, can you open the cache with a text editor and ensure it’s what you expect? Hope that helps!

  7. Nice, altough it has the same problem as every other Last.fm-Plugin that i know: I have to choose what to display in the settings.

    Why not make this an parameter to fmtuner();?
    That way i could easily display everything i want using only one plugin.

    I have described it in more detail in the comments over there: http://leandrow.net/ilastfm-lastfm-wordpress-plugin/#comments

    Any chance you’ll be adding “top tracks”, “top artists”, “top albums” etc and giving us the opportunity to display multiple instances by using it like:

    ===

    My Top Tracks:
    fmtuner(’tracks’);

    My Favorite Albums:
    fmtuner(’albums’);

    I’m a fan of:
    fmtuner(’artists’);

    ===

    That would easily make your Last.fm-Plugin THE outstanding one out there.

  8. @AgentSmith: That’s a good point! I had assumed it would only be used in one place, but with an added parameter, it could be used multiple times on a site, each with different options.

    You can currently choose Top Tracks, but not the other two.

    I’ll see what I can cook up :)

  9. I keep getting this error.
    Fatal error: Call to undefined function: file_put_contents() in /homepages/42/d161646578/htdocs/home/wp-content/plugins/fmtuner/fmtuner.php on line 237

  10. @Collin: “only tracks with artwork will be shown” is a dangerous option. My case was that no artwork-powered tracks were cached and thus zero output produced.

    Still thanks for a great plug.

  11. A FAQ for this might be nice. For example… i got an error message telling me:

    Settings Saved - syled nicely… then in plain text underneath >
    Call to undefined function: file_put_contents() in /homepages/15/d117163260/htdocs/wordpress/wp-content/plugins/fmtuner/fmtuner.php on line 237

    I put the php code in my sidebar include BEFORE any of the if statments for widgets — just to be safe.

  12. @Jake @Joel_: file_put_contents() is a PHP 5 function. Are you by chance running PHP < 5?

    The WordPress plugin page linked to above has a small FAQ that is due for some updating now that the plugin is in the wild :) I’ll be updating it soon with solutions and problems covered in comments here.

  13. Yeah just realized I have php 4 and have no idea how to upgrade with 1and1.com

  14. After some looking I have php5 but I am still getting the same error, but its on line 236 now.

  15. fmTuner: A Last.fm Plugin for WordPress…

    fmTuner is a small WordPress plugin for retrieving song details from your Last.fm profile and publishing them anywhere in your WordPress theme. It provides options for choosing among your Recent, Loved, or Top tracks, as well as tools to adjust the upd…

  16. WordPress 2.6.2 Update
    I just tested fmTuner with WordPress 2.6.2, and it appears to be working just fine, as seen here at Command-Tab.

  17. @Rogie King: yes, that’s what i meant

  18. Oh… I’m 1and1.com also… but I thought for sure they supported both php 4 and 5!

    shoot.

  19. Yo Collin,

    Any plan to release this for php4? What is the dependency? Is it the caching or is it the XML libs needed?

  20. I plan on porting it to PHP 4 for a future release, as the dependency on PHP 5 is solely for the XML parsing that comes built-in. It shouldn’t be terribly complicated to find (or write) a basic XML parser for PHP 4 and get things rolling :)

  21. thanks for the info. Everyones responses have been helpful as well.

  22. actually, i did find out how to activate php5 for 1and1 hosting… but it turns out the php init settings do not support that external URL call you make… (even though it might very well handle the xml parsing).

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /homepages/15/d117163260/htdocs/wordpress/wp-content/plugins/fmtuner/fmtuner.php on line 248

    somehow, I doubt there would be a work-around for this… I’m pretty much stuck with the PHP config my host gives me, right? Any thoughts?

  23. @Joel_: You might be able to drop in an ini_set() call before file_get_contents() is called: ini_set(’allow_url_fopen’, ‘on’);

    Otherwise, you might have to get in touch with 1and1 to see if they can update your config…

  24. it was a great post. i am coming to know about wordpress recently only. great to know that wordpress has these features. will switch one day. thanks.

  25. The plugin does not work for me…
    Yes, I am running PHP5. Wordpress 2.6.2

    Nothing will show up in the template. I get this at the top of my fmTuner settings page:

    ==================

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /mnt/local/home/jomilla/jomilla.com/wp-content/plugins/fmtuner/fmtuner.php on line 248

    Warning: file_get_contents(http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=jomilla&api_key=ff0eaca3b7e2660755d6c652af7b0489) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /mnt/local/home/jomilla/jomilla.com/wp-content/plugins

    =====================

  26. @Jordan: It seems your web host has URL-based file access turned off for some reason. You can try the ini_set solution I gave to Joel (above), and if all else fails, your web host might be able to turn it on.

  27. I’m not sure if I’m that big of a noob, But could you give me some clearer directions? In the meantime I will contact my web-host. Oh, and thanks a ton! :)

  28. And I got this back from my hosting company for the record:
    Hello Jordan,

    The reason this is disabled is because there is a security issue with URL
    based file access specifically url_file_open.

    We can’t change the global PHP settings, but you’re more than welcome to
    install a custom PHP instance if you’d like:

    http://wiki.dreamhost.com/Custom_PHP.ini

    I apologize for the inconvenience.

  29. ’m not sure if I’m that big of a noob, But could you give me some clearer directions? In the meantime I will contact my web-host. Oh, and thanks a ton!

  30. Got it working! Thanks a lot! Is there any pre made templates for this? or suggestions on building a template??

  31. Hi,

    can’t get the plugin running! Cache correctly downloaded, but
    no output.

    I placed

    in my SIDEBAR.PHP. No output. Where do i have to place the
    function-phrase and how cant i customize the output?

    Sven

  32. I wrote an ASP.NET User Control that provides a similar functionality for any of those out there looking to do this on an ASP.NET page. Hop on over to http://www.dscoduc.com/post/2008/10/09/lastfm-ASPNET-User-Control.aspx for a look and your copy.

  33. Hey any chance on telling us how to style these like yours I want mine to look simelar but I can’t get it quite right. :P great plugin btw exactly what I needed

  34. fmTuner works great with my wordpress…. And I am also using it via OpenSocial on my ning network i have set up for my site!

  35. Thanks for the plugin. I’ll check it out.

  36. I’m not toooo familiar with php stuff. Do I put the code in the sidebar php?

  37. thank you

  38. Thank you . This is really great

  39. Great job. Thanks for the plugin.

  40. I am not familiar with PHP. Any step by step instructions for getting this into the sidebar? It doesn’t seem like it would be too difficult but I have yet to get anything to display. I do know it is installed correctly.

  41. @Scott @Dave: Once fmTuner is installed, activated, and set up (enter your Last.fm username in the fmTuner Settings page), open up /wp-content/themes/default/sidebar.php with a text editor like Notepad or TextMate. Around line 53, add in:
    <li><h2>Tunes</h2>
    <ul>
    <?php if(function_exists('fmtuner')) { fmtuner(); } ?>
    </ul>
    </li>

    Save the file, and reload your blog in a web browser. This will call up fmTuner within your sidebar!

Leave a Reply