How to add Digg This to your WordPress posts
This technique doesn't use any Blog Client plugins, and doesn't use any WordPress plugins.
All I wanted was a Digg This badge on my individual posts, that links to the Permalink not the the actual domain name.
The Windows Live Writer Digg This Plugin can't do this, and the WordPress plugins were to bulky. Also I couldn't manage to set them up to look good on my current theme.
There were two possible answers to this little predicament, that I could think of.
- Add a code snippet to each and every blog post, which would require me re-editing the post when I had the Permalink for it. Obviously to much work.
- Add the Digg This script to the theme.
Option 2 seemed the best, because I am most certainly going to stick with this theme.
Anyway, what I have done is basically edited the JS a bit, so that the link will always be directed to the Permalink, even on the main page. If you don't set the digg_url value then the JS will take the link from window.href.
Here is the modified code:
<div style="float:right;"> <script type="text/javascript"> digg_url = '<?php the_permalink() ?>'; </script> <script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script> </div>
EDIT: The code above seemed to be crashing IE7. Something to do with downloading the same JS file over and over? I have no idea. It worked in FireFox though.
Here's the updated code, which is basically the same but with the diggthis.js file downloaded and added to the code.
<!--- DIGG THIS CODE! --> <div style="float:right;"> <script type="text/javascript"> digg_url = '<?php the_permalink() ?>'; (function(){var ds=typeof digg_skin=='string'?digg_skin:'';var h=80;var w=52;if(ds=='compact'){h=18;w=120;} else if(ds=='icon'){h=16;w=16;} var u=typeof digg_url=='string'?digg_url:(typeof DIGG_URL=='string'?DIGG_URL:window.location.href);document.write("<iframe src='http://digg.com/tools/diggthis.php?u="+ escape(u).replace(/+/g,'%2b')+ (typeof digg_title=='string'?('&t='+escape(digg_title)):'')+ (typeof digg_bodytext=='string'?('&b='+escape(digg_bodytext)):'')+ (typeof digg_topic=='string'?('&c='+escape(digg_topic)):'')+ (typeof digg_bgcolor=='string'?('&k='+escape(digg_bgcolor)):'')+ (ds?('&s='+ds):'')+"' height='"+h+"' width='"+w+"' frameborder='0' scrolling='no'></iframe>");})() </script> </div> <!--- DIGG THIS CODE! -->
All you need to do now is put it after the H1 tag for the post title. It will float on the right.
EDIT: Here are the locations in "Theme Editor" which I added the code after <h1>...
- Archives
- Main Index Template
- Single Post
Hope someone finds use of this!