How To Display Your Feedburner Count And Twitter Followers Without Chicklets

Posted in Tutorials | On 5th February 2010 | 16 Comments


Feedburner offers a great chicklet which allows you to add your subscriber count to your site, and for Twitter you can use a chicklet to display your followers from a service such as twittercounter.com.

What I’m going to show you today is a method of displaying these counts without actually using a chicklet which will allow you to customise how your stats will be displayed.

We will be using PHP to grab the data you need, then you can style with CSS within your own site, Please backup any files before editing them!

FeedBurner

This following code grabs the data from feedburner using the awareness API, replace “YOUR FEED ADDRESS” with your feedburner feed address, e.g. WebM-ag

<?php
$url = file_get_contents('https://feedburner.google.com/api/awareness/1.0/Get
FeedData?uri=YOUR FEED ADDRESS');
$begin = 'circulation="'; $end = '"';
$page = $url;
$parts = explode($begin,$page);
$page = $parts[1];
$parts = explode($end,$page);
$fbcount = $parts[0];
if($fbcount == '') { $fbcount = '0'; }
echo '<b> '.$fbcount.' </b> Subscribers';
?>

This will echo out the count, e.g. 399  Subscribers.

Twitter

This code uses the Twitter API and grabs its count from a XML feed, replace “USERNAME” with your Twitter username, e.g. webmagz

<?php
$twit = file_get_contents('http://twitter.com/users/show/USERNAME.xml');
$begin = '<followers_count>'; $end = '</followers_count>';
$page = $twit;
$parts = explode($begin,$page);
$page = $parts[1];
$parts = explode($end,$page);
$tcount = $parts[0];
if($tcount == '') { $tcount = '0'; }
echo '<b> '.$tcount.' </b> Followers';
?>

This will echo out your follower count, e.g. 712  Followers

All Done

That’s pretty much the bare bones code you need to get started, you can of course style it in any way you wish, as it uses PHP your page extension MUST be .php (not .html  etc…) or within WordPress it will work without altering any page extensions.

Demo

Here is a very basic styled demo which is available to download in a .ZIP file

DEMO | DOWNLOAD

McBonio is a full time web designer, blogger and general web lurker. He runs Tropica Web Design, which is a web agency based in Liverpool, UK. You can also catch McBonio at Twitter: @mcbonio

Visit McBonio's website

16 Comments

  • Shurandy Thode
    February 5, 2010
  • Eko Setiawan
    February 8, 2010
  • Sergej Müller
    February 8, 2010
  • McBonio
    February 8, 2010
  • System Dioxide
    February 10, 2010
  • Laneth Sffarlenn
    February 11, 2010
  • McBonio
    February 11, 2010
  • Laneth Sffarlenn
    February 11, 2010
  • Laneth Sffarlenn

    Hey McBonio, thanks for the response. When I learn a bit more about this sort of thing, I’ll know just what to do :) Thanks for your help!

  • McBonio

    Hi Laneth, you can use it without HTTPS and the result is the same, the demo is running on HTTPS and works fine.

    I would suspect there might be something on your hosting/server preventing the https working correctly. (or maybe in your WP .htaccess?)

    Here is a demo without https: http://www.webm.ag/tuts/fbtwit/tut1.php

  • Laneth Sffarlenn

    For some reason when entering the Feedburner script, I cannot use the HTTPS formatting, as it returns not only the actual result but an error string also. I can’t figure it out – I remove the “S” from the http and it works fine, but it won’t work for me (in WordPress) with HTTPS.

    Have I done something wrong with it, or am I right to use it without the HTTPS? (Sorry, PHP n00b here)

  • System Dioxide

    Thanks! It works like a charm.

  • McBonio

    Hi Sergei,

    Yeah I left out caching, I aimed to keep it basic so the code could be expanded on, perhaps databased and run on a cron if needed :)

  • Sergej Müller

    Without caching? See http://wordpress.org/extend/plugins/bitly-retweet/ with internal cache for more blog performance.

  • Eko Setiawan

    I will use this on my homepage, thanks for share…

  • Shurandy Thode

    Great work explained thanks for sharing.