How to: Display how many times a post has been saved to Delicious

Are your blog posts popular? A good way to know it and take advantage of it is to display your Delicious.com save count. Sure, they provide a badge which allows you and your readers to know how many time your post was saved. In my opinion, the badge is ugly. Let’s display our save count in plain text!

To get your Delicious save count in plain text, simply open the single.php file from your theme and paste the following code where you'd like the count to be displayed.

Delicous.com saves: <span id='del'>0</span>

<script type='text/javascript'>
function displayURL(data) {
    var urlinfo = data[0];
    if (!urlinfo.total_posts) return;
    document.getElementById("del").innerHTML = urlinfo.total_posts;
}
</script>

<script src='http://badges.del.icio.us/feeds/json/url/data?url=<?php the_permalink() ?>&callback=displayURL'></script>

Getting our Delicious save count isn't hard at all. On this exemple, I have created a html element with a specific id and then imported a script from delicious. Once the script is loaded, I executed a function to replace the initial zero with the current number of saves for the specific item.

If you'd like to allow your users to directly save your posts to their delicious account without leaving your blog, you should read this recipe.

2 Responses

Jan 12 2009 17:25

STUMBLED!

This is exactly what I need, thanks for posting.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required