Adding Del.icio.us to Wordpress Blogs
| Thursday, December 21st, 2006 | --jr |
What? No crappy pun? Ah well...
So Del.icio.us recently released a new widget that allows you to make adding pages to del.icio.us even easier. Naturally, I wanted to add it here. What's more, it gave me a chance to poke around in the code and discover a few things.
First a few words about Wordpress. If you haven't created a custom theme yet, you really need to. It's not hard, and it makes things like this not disappear when you upgrade next time.
Ok, now that you've done that, the bits you need to add are pretty straight forward. In your brand new theme directory, you need to modify index.php and single.php.
Near the top of the file add:
<script type="text/javascript">
if (typeof window.Delicious == "undefined") window.Delicious = {};
Delicious.BLOGBADGE_DEFAULT_CLASS = 'delicious-blogbadge-line';
/* Set manual mode so that we can have multiple badges */
Delicious.BLOGBADGE_MANUAL_MODE = 1;
</script>
See that last line? That's kinda key. That's what keeps the script from running instantly.
Inside the post loop, add:
<script type="text/javascript">
Delicious.BlogBadge.writeBadge('delicious-blogbadge-<?php the_ID(); ?>',
'<?php print get_permalink(); ?>',
'<?php print preg_replace('/\'/',"/\\'/",get_the_title()); ?>', {});
</script>
and then, near the end of the page add:
<script>
Delicious.BlogBadge.onload();
</script>
That sets things in motion.
So, what's it do? Well, it adds that thing at the bottom, and customizes it to point to the specific post's URL and use the right title.
Easy? You betcha! Thanks Del.icio.us folks!
December 21st, 2006 at 1:55 pm
That’s a cool hack and all, but man - the bottom of the posts are starting to look like junk….there really needs to be a better way to help the developing state of Iconistan. Any chance of creating a drop down permalink that doubles a Digg/Submit to Del.icio.us/etc…?
December 21st, 2006 at 4:31 pm
Cool! Can we also get an overall del.icio.us badge for the top page (ie, gives tags and stats for http://ycoolthing.com)? I want to see what sort of tags people are giving us!
December 21st, 2006 at 4:38 pm
Adam,
Yeah, I hear you about how the page is getting loaded up with stuff. I’ll try to putter around and come up with some solution for it. One thing that I’ve noticed, however, is that people tend to ignore stuff that’s not right in front of them.
Personally, i’m a HUGE fan of live clipboard (here’s a link, you go do something clever with it), but it’s not quite “there” yet. I’ve got a few ideas and it’ll give me something to do over the holiday break.
Sean, I may add it to the top page, but I’m thinking it might be a tad busy. I may modify it a hair and just put up the things that are really interesting to us.
December 21st, 2006 at 8:12 pm
Yeah, I looked over the tags for us anyway and I didn’t see “remarkablyhandsome” among them, so no great loss if we don’t feature it prominently.
Mainly, I just wanted to point out that, while this is a handy feature for encouraging people to tag your blog posts into del.icio.us, I think that it really shines in the sense that it allows you to instantly add CONTEXT to any of your webpages. If you add this badge to the top page of any site, visitors can instantly get a feel for what your site is all about by examining the tags that other people have submitted. That’s really, really cool to me.
December 24th, 2006 at 4:51 am
Cool hack :) I’ve use it in my Word Press Plugin: http://www.ivanuzunov.net/delicious-tagometer-badge-wp-plugin/