• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Custom Digg Counter in WordPress with PHP ...

You will notice in the lower right corner of this entry that there is a reference to the number of Diggs for this post.

You will notice in the lower right corner of this entry that there is a reference to the number of Diggs for this post. If you click the counter you are taken to Digg. Digg does offer a few easily integrable scripts at http://digg.com/tools/integrate but does not document how to create a custom counter. To accomplish this you need to use the Digg API which is very easy to work with. There is no registration and your access key is simply the source domain. This example is customized for WordPress but can easily be modified to work in any PHP based project.

Here is the PHP function to grab the number of Diggs from the Digg API.

function getDiggs($url) {
$sturl = http://services.digg.com/stories?link=.$url.&appkey=
http%3A%2F%2Fwww.yourdomain.com&count=1;
$ch = curl_init($sturl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,"www.yourdomain.com");
curl_setopt($ch,CURLOPT_TIMEOUT,10);
$res = curl_exec($ch);
$resinfo = curl_getinfo($ch);
curl_close($ch);
if($resinfo[http_code] === 200) {
preg_match(’/diggs=”([0-9]+)”/si’, $res, $r);
$diggs = number_format(($r[1]) ? str_replace(’,, ”, $r[1]) : ‘0′);
if($diggs == 1) {
$response = $diggs .’ Digg’;
} else {
$response = $diggs .’ Diggs’;
}
} else {
$response = ‘Error’;
}
echo $response;
}

If you plan on displaying your Diggs on multiple pages create a folder in your theme directory and include the file with the following…

<?php include(TEMPLATEPATH ./folder/script.php); ?>

Setup the variables to build the Digg link and the URL to pass to the PHP function. This will use the current post URL in a loop or on a standalone page so there is nothing to hardcode.

$diggurl = urlencode(get_permalink($post->ID));
$diggtitle = urlencode(get_the_title($post->post_parent));
$digglink = http://digg.com/submit?url=.$diggurl.&title=.$diggtitle;

Finally add the link, in my case I have positioned the reference in the bottom right of the post and added a bubble comment background to the link with CSS. In the href I am passing the encoded link and the encoded title to Digg. You can also pass through the media type, description, and topic if you want. Click here for details.

<a href="<?php echo $digglink ?>" class="diggticker"><?php getDiggs($diggurl); ?></a>

source: leigeber

 View Full Story.
Posted at 10:05:20 am | Permalink | Posted in Digg  

Related Stuff

Improving security in Wordpress plugins using Nonces

Using a nonce (number used once) is the best way to protect your plugin against a cross-site request forgery (CSRF) hacker-attack. Nonces ...

10 New WordPress Plugins

This plugin enable admin to put up a splash page to show that the site is down for maintenance. Come with a timer to tell how long the site ...

WordPress Forums Plugins To Build Community

Growing your blog beyond publishing can be done quite easily by using WordPress Forums Plugins. Community growth greatly depends on ongoing ...

5 Annoying WordPress Plugins

Usually I attempt to share useful WordPress information but today, I thought we could have some fun with 5 of the most annoying WordPress ...

New releases for jQuery and Wordpress

The jQuery Database plugin takes your HTML tables and allows you to write a query against them similar to MS- or mySQL. I haven’t had ...

1 Comment |Add your comment.

Aquarium Fish said:

Ive already seen this article advertised on the other site it was taken from. The instruction to use are very vauge though

Posted at October 24, 2008 09:58:02 am

Your Comment ...

  Name (required)

  Email (required, hidden)

  Website


Top Stuff

Free Blogger templates Anime Themes

Wordpress Guestbook Generator Plugin

GeekLog

Zookoda

Introduction to blogs and blogging

jumpcut


Our Partners

Facebook Applications

Ajax Projects

Web 2.0 Sites

Webloglines

Human Development Handbook

Software Development Company

Ajaxlines

Stock Exchange Chat


About Webloglines

Webloglines is a project offers a comprehensive collection of blogging services, articles, themes and plugins from around the world. Whether you're looking to promote your own blog or find blogs on various topics, this site is for you.


Search


Topics

  • Adsense (9)
  • Blogging Tips (59)
  • Blogs Slides (25)
  • Blogs Websites (22)
  • Digg (8)
  • How to Blog (65)
  • Search Engines (2)
  • SEO (40)
  • WordPress Plugins (88)
  • WordPress Security (28)
  • Wordpress Themes (36)
  • Wordpress Tips (56)

© 2006 www.webloglines.com. All Rights Reserved. Powered by IRange