Display Feedburner and Twitter Stats in your Thesis Theme

by Ashwin

in Thesis Theme, Wordpress

Got bored of the traditional Feedburner Feedcount image?  Stuck with the Twitter Plugins that claim to display the number of followers in your blog? Forget them all.  I will show you how to get the Feedburner and Twitter subscriber stats programmatically (using PHP) in your Thesis powered blog and display them at your convenience.  This can also be used on a Wordpress blog running any theme, with ease.

1.  Modify your custom_functions.php file

Let us first create a couple of functions in the custom_functions.php, that would do us the job of fetching the numbers.

You can find the custom_functions.php file under the following directory – Your Blog Theme Directory/custom/custom_functions.php

function get_feedburner_stats() {
  $fbrefreshtime = 43200;  //Refresh Feedburner twice in a day

  $fb = wp_cache_get('fbstats_key');

  if ($fb == false) {
    $yourfeeduri = 'ThoughtsUnlimited'; 
    $feed = 'https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri='.$yourfeeduri;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $feed);
    $feed = curl_exec($ch); curl_close($ch);
    $xml = new SimpleXMLElement($feed);
    $fb = $xml->feed->entry['circulation']; 

    //Set the Value in Cache
    wp_cache_set('fbstats_key', strval($fb), '', $fbrefreshtime);
  return $fb;

function get_twitter_stats() {
  $twitterrefreshtime = 54000;  //Refresh Twitter Stats once every 15 minutes

  $tw = wp_cache_get('twstats_key');

  if ($tw == false) {
    $yourtwitter = 'thotsunlimited';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $twurl);
    $data = curl_exec($ch);
    $xml = new SimpleXMLElement($data);
    $tw = $xml->status->user->followers_count; 

    //Set the Value in Cache
    wp_cache_set('twstats_key', strval($tw), '', $twitterrefreshtime);  //Will expire after the Refresh time you set
  return $tw;

Make sure that you replace the $yourfeeduri and $yourtwitter values, with your own values

Updated on 08/05/2009:

Modified the Code to cache the numbers using WP_Cache, as excessive API calls might be unsuitable for blogs with many page views per hour. Thanks to Christian for pointing this out here.

Enable WP Caching, by adding define(‘WP_CACHE’, true); to your wp-config.php file. Check this out, for information on enabling the WP Cache

Make double sure that you enable the Awareness API for your Feedburner Account


2.  Call the function wherever you need and style the output

So now you have the way to get the numbers.  Call them from anywhere you need and appropriately style the output.  I would recommend using the Thesis OpenHook plug-in to place the output of these functions.

Calling the function is pretty straightforward. One example could be:

 Join the fleet of  Subscribers 

You can look at the sidebar of my blog, to see one other example in action.

Hope you found this useful. Add any useful extensions to this tip, as comments to this post.

  1. Create a Full-Height Sidebar and Full-Width Navigation Menu in Thesis Theme
  2. Search Box in Navigation Bar of the Thesis Theme
  3. Thesis Theme : Setup Pagination on Home Page

Stay In The Loop!

 Subscribe to our RSS Feed
 Join on Twitter
 Get Posts via Email

  • manavecplan
    Hi Ashwin,

    Is this the same kind of code that Chris uses on Blogussion?
  • Ashwin
    Sorry not really sure about the code in Blogussion.

blog comments powered by Disqus

Previous post:

Next post: