Adding Digg Links To Certain Posts In WordPress

The last few days I have been improving this blog, adding more interesting blogs, BlogRush widget as well as some changes in the code (i.e fixing the navigation rollover).

I have added some code to the posts that shows a ‘Digg This’ link on posts I have submitted to Digg and only these posts. This can be seen on the bottom of my EyeTV Hybird Review and this post. This uses 1 wordpress custom field and some PHP in the WordPress theme files. You may or may not want to use this method of adding Digg links to your blog but this one works for me and I wanted to share.

This only allows people to digg posts you have submitted yourself, its not a way of allowing people to submit your posts to digg themselves. If you want to do this search Google or try this.

Open your WordPress theme’s index.php file. Then find the section of code where you want to display the Digg link. Make sure its in The Loop. Then paste the following code within PHP tags and removing the spaces in the link.

$values = get_post_custom_values("Digg");
if ( $values != "" ) {
echo "< a href=' ".$values[0]." '>Digg This< /a>";

As you can see it uses the get_post_custom_values() tag to get the value of a custom field named Digg.

Now navigate to your Blogs WordPress Admin Area and find the post you want to add a Digg link too, once on this page navigate down to a section named ‘Custom Fields’. Now you want to fill in the form with Digg as your Key and the Digg URL as your Value like this. Once thats done then click the ‘Add Custom Field’ button and you should have a post with a Digg This link. Its then up to you how you want to style it, you can edit the PHP to make it display how you want.

Once your first post has been done next time you simply need to navigate down the the Custom Fields section and select Digg in the dropdown menu and add your Digg link to the value and then click the ‘Add Custom Field’ button and that post will have its Digg This Button. Of course you can only add the Digg custom field in after you have posted it to Digg.

Now why did I decide to do this instead of add Digg links to all posts?

Well some of my posts I don’t really want digging so I decided the ones I do want digging I will submit myself and use the above method to quickly add the Digg link to the particular post.

I will be editing this post to display the code better when I get the chance.

Any problems or comments feel free to submit them.

Join the Conversation


Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.