top
10
05
2008
16:54 pm
filed as: General, Wordpress
author: Dejan Cancarevic
comments: Subscribe
9 Responses

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() ?>& amp;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>

Ruestions, problems? Post them here in comments

Subscribe full RSS RSS
  • del.icio.us del.icio.us (0)
  • StumbleUpon StumbleUpon
  • Digg Digg
  • Mister Wong Wong it
9 Responses, Leave a Reply
9
SARAH
May 13th
2008
11:40 am

No doubt, this is really great. Thanks for sharing

8
Ozh
May 11th
2008
14:10 pm

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.

7
Brian Purkiss
May 11th
2008
2:21 am

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

6
Dejan
May 10th
2008
21:23 pm

@ 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…

5
kremalicious
May 10th
2008
18:42 pm

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

4
kremalicious
May 10th
2008
18:29 pm

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?

3
James
May 10th
2008
17:43 pm

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.

2
Marko
May 10th
2008
16:58 pm

nice and easy :)

1
Steve
May 10th
2008
16:57 pm

oh, really cool, thank you!

What do you think?

Name (required)

Email (will not be published) (required)

Website

About

StylizedWeb is blog about web trends and tutorials and KnowHow community forum designed and maintained by Dejan Cancarevic.

Six Shooter Media
logo and web site design

Search