As you know, Digg is a powerful social website which can send more than 10,000 visitors to your blog if your article is pushed to the front page.
We can easily add the Digg button to our posts. All you need to do is simply copy the code and paste it into your template file and then the Digg button will appear in every post. But what if you only want the Digg button to appear in selected posts only?
How to make the Digg button appear in selected posts only
So, I am going to create a custom function and use custom fields to decide whether the Digg button will appear or not.
Open your template’s functions.php and paste the following codes before the ending tag ‘?>‘.
/* Return a Digg button */
function digg_button()
{
global $post;
$link=js_escape(get_permalink($post->ID));
$title=js_escape($post->post_title);
$text=js_escape(substr(strip_tags($post->post_content), 0, 350));
$button="
<script type='text/javascript'>
digg_url = '$link';
digg_title = '$title';
digg_skin = '$mode';
digg_bodytext = '$text';
</script>
<script src='http://digg.com/tools/diggthis.js' type='text/javascript'></script>";
if (get_post_meta($post->ID, 'digg-button', true) == 1)
echo $button;
else
echo '';
}
Then, open your single.php, and add this code at the place where you want Digg button appear.
<?php digg_button(); ?>
So now that you have added the necessary code, simply add a custom field called “digg-button” with value 1 to the post that you want Digg button to appear.
Now, you can easily show or hide the Digg button using a custom field!
Feel free to add my Digg acount







Thanks, that's a great use of a custom function as well!
good one…………..thats perfect………..
Hi,
Instead of a custom-field, I've created a plugin at http://ajaydsouza.com/wordpress/plugins/digg-inte… that integrates the javascript supplied by Digg themselves.
Really an good tip.. Thnks for sharing it with us
Awesome, I've been looking for something like this. It's good to get some diggs but some posts just aren't suitable and it will be nice to be able to exclude them.
Hi all,
Thanks for reading my tutorials. I will try to improve it so that it can show different digg button based on your selection. Make sure you follow my feed or bloggingtips closely so that you won't miss this plugin!
great, always wanted to know how to do this, just bookmarked your site for fututre refrence.