Thursday, October 2, 2008

Dashboard - How to display your RSS subscriber count

How to display your RSS subscriber count

You've all seen the little FeedBurner subscriber counters on sites that display a site or more often a blogs number of RSS subscribers. Whilst this is a nice widget to display on your site there isn't much in the way of customizing to display something different.

Plaint text subscriber count

There is a way to display the number of readers you have for your feed by using FeedBurners API. This means you can display your subscriber count within some text, for example as part of a blog post. You could also have a separate message somewhere on you site saying X number of readers subscribe to this site.

You can use the PHP code below. You need to have PHP5 otherwise the SimpleXMLElement command will not work.

//get cool feedburner count
$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=YourFeedburnerFeedLinkHere";

//Initialize the Curl session
$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);
//Execute the fetch
$data = curl_exec($ch);
//Close the connection
curl_close($ch);

$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];

//end get cool feedburner count
?>

The next line of PHP needs to be located where you want the subscriber count number to appear. This code needs to occur after the code above for it to work.

I borrowed this code from Mark over at 45n5 so thanks Mark.

This post is from the Newsniche website and should not be reproduced elsewhere. Why not subscribe to the RSS feed and get this information delivered straight to your News reader.


No comments: