Top Ad unit 728 × 90

Add Digg Buttons in Your Posts using Custom Fields


Doesn’t it get annoying posting digg buttons on your articles every time. But you don’t want to display them on every page by default because some articles are not digg worthy. Well this solution would be very helpful then. In this plugin, you will add the codes in your single.php once, and in each article that you want to display the button, you will just have to enable it using the custom field.
First open your single.php and find a code that looks like this:
1<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Replace it with:
1<?php if (have_posts()) : while (have_posts()) : the_post();
2// check for digg button for single page
3$digg = get_post_meta($post->ID, 'Digg'$single = true);
4?>
Now you need to add the following code within the loop anywhere you like:
1<?php // if there's a single page digg button
2if($digg !== '') { ?>
3<script src="http://digg.com/tools/diggthis.js"type="text/javascript"></script>
4<?php } // end if statement
5// if there's not a digg button
6else echo ''; } ?>
You may wrap it around with any styling that you want. Save the single.php and upload it to your theme folder.
Now when writing a post if you want to add a digg post simply add a custom field like shown in the screen shot below:
Whenever you specify this custom field, WordPress will display a digg button on your post.
Add Digg Buttons in Your Posts using Custom Fields Reviewed by Unknown on 1:32 AM Rating: 5

No comments:

All Rights Reserved by Boca Raton Real Estate © 2014 - 2015
Powered By Blogger, Designed by Sweetheme

Contact Form

Name

Email *

Message *

Powered by Blogger.