StylizedWeb is a web design trends and tutorials blog, maintained by Ross Johnson who also runs a web design company and design blog.

Categories Archive

Popular Posts
Advertisement
Premium WordPress Themes, Theme Galaxy Basecamp
Najbolje ponuda IT poslova u Srbiji na itposlovi.info Advertise on Stylized Web

Plain del.icio.us count

add to Save to Delicious Save to Stumble Save to Digg

Now when we have learned how to customize your count for RSS and Digg it's time to learn how to do it for del.icio.us like I'm using on my themes page for example. As del.icio.us is in top 3 you just have to have it for bookmarking services because it usually gives most of the traffic right after StumbleUpon.

Plain del.icio.us count

To make your count into plain text (for now and then you can do with it what ever you want) we'll use small JavaScript and del.icio.us JSON feeds (read more about it here). You can see all kind of other services in your del.icio.us. setting account (for example network badges etc). So, let's start with the code.

Since you are probably going to use this with WordPress i'll be using it for example too. So to bookmark something to del.icio.us you are using code similar to this:

 
<a href="http://del.icio.us/post?url=<?php echo get_permalink() ?>&title=<?php the_title(); ?> "> save to del.icio.us </a>
 

Now where you want to have the count add this line (i have added it in span next to link) and just past this JavaScript under it and you're done ;)

 
<span id='<?php echo md5("http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]);?> '>0</span>
 
 
<script type='text/javascript'>
function displayURL(data) {
var urlinfo = data[0];
if (!urlinfo.total_posts) return;
document.getElementById("<?php echo md5("http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]);?>").innerHTML = urlinfo.total_posts;
}
</script>
 
<script src='http://badges.del.icio.us/feeds/json/url/data?url=<?php the_permalink() ?>&callback=displayURL'></script>
 

Questions, problems? Post them here in comments

Have some feedback? Leave a comment



What do you think?





12 Responses so far

By Dejan Cancarevic
on July 27, 2008

Wallace
I use it on top of my page…

By Wallace Rodrigues
on July 27, 2008

It would be nice to get a “fool-proof” version of this counter, because I spent almost two hours on this without getting it to work…

I’m trying to show counts on my index page though, I don’t mind if it shows two or more numbers instead of the absolutely correct one.

It just won’t work…

By SARAH
on May 13, 2008

No doubt, this is really great. Thanks for sharing

By Ozh
on May 11, 2008

People need to be more aware that they *need* a syntax highlighting plugin, that will fix the curly quotes & stuff that WP puts everywhere.

I’ve been using iG Syntax Hilite for about 3 years now and it’s great.

By Brian Purkiss
on May 11, 2008

Very nice…
I’ll probably end up using that for my next design…

By Dejan
on May 10, 2008

@ James
Yes, sorry about that WordPress does it ;)

@ kremalicious
Well, it can work on index page but it doesn’t display count correctly, as you mentioned (starts from number two or something like that as i remember) and i don’t think i have a solution for it…

By kremalicious
on May 10, 2008

just to add: firebug and Safari’s Web Inspector display an error with this line:
if (!urlinfo.total_posts) return;

By kremalicious
on May 10, 2008

Nice quick and easy tutorial. but how to implement the correct number count on an index.php template with different posts on one page? in such a case the REQUEST_URI function will use the blog url and not the post url. is there a way to replace it with something like to get it to work on pages with more than one article?

By James
on May 10, 2008

Great little tip, I loved it. The only problem I had was the quotes ‘ and double quotes ” got a bit mixed up as I copied and pasted. I just had to go through an change that bit of code.

By Marko
on May 10, 2008

nice and easy :)

By Steve
on May 10, 2008

oh, really cool, thank you!

  1. Oct 7, 2008: 5 Trends of Popular WordPress Blogs- Part1