Add Digg It Badge to Wordpress
I just recently added the Digg It buttons on here. I had to do some debugging to try to get it to work properly, so I figured I’d pass along my work for anyone else to use. There are two things that I did to make it work right:
- Modify the posts loop on the template pages I wanted the badge to appear on. In my case this was the index.php, single.php, and page.php templates.
- I encapsulated the Digg code in a DIV so I could style it up.
This snippet of code below is what you will want to put in your posts loop, right above the <?php the_content(); ?> function call. I chose to include the digg_url and digg_title JavaScript variables.
The digg_url variable is required if you are going to place the badge in your index.php template, or any template where it is possible to see multiple posts e.g. archives.php. What it does is encodes each badge with the permalink for the appropriate post, rather than using the URL of the page you are currently viewing. I decided to include digg_url on single.php and page.php for consistency. The digg_title variable pre-populates the Story Title field for the first person to Digg the post.
<div class="diggit"><script type="text/javascript">
digg_url = '<?php the_permalink() ?>';
digg_title = '<?php the_title(); ?>';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div>
<?php the_content(); ?>
Now for the CSS stuff. For my template I only needed to float the DIV to one side — I chose left — and modify the padding options to get it in position.
.entry .diggit {
float:left;
padding: 20px 5px 0 0;
}
The general information for this came from the Digg Tools Integration section. I added in the necessary Wordpress PHP functions in order to fill in the JavaScript variables. Try it out and let me know how it goes.
Mar 16th 2007
The DiggClick (http://codehack.biz/wordpress/diggclick/) did the trick nicely in my case.
I used to modify the templates, but I use more and more plugins as they go on working when one day you decide to change the theme.
Anyway, it is always interesting to get in touch with how wordpress templates work !
Mar 21st 2007
I completely understand what you are talking about with the theme hacks, only to change themes and have to remember all of what you did. It took me a long time to even explore widgets because, well, it was “too simple and easy.” I like digging around in the WP templates. Until I realize, “Aw crap, I forgot to add this call to my new theme.” I tend to be a hack-the-code-first-then-look-to-what-someone-else-has-done kind of guy. Someday I’ll learn.
That said, I’ll have to look into DiggClick a little more. On my initial look the only apparent differences were that DiggClick doesn’t pre-populate the story title, and it references a different JavaScript file. There again, I could be missing the boat on something.
Apr 19th 2007
OK, but i still can not use in my website