How to display your average feed readers

by Hieu Martin on August 10, 2010

Many bloggers are using Feedburner “chicklet” to display their subscribers count. If you want to be able to display the count for an average 7 days, here is a piece of code you’re going to love.

As usual, the first thing to do is to paste the function in your functions.php file:

function get_average_readers($feed_id,$interval = 7){
	$today = date('Y-m-d', strtotime("now"));
	$ago = date('Y-m-d', strtotime("-".$interval." days"));
	$feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL, $feed_url);
	$data = curl_exec($ch);
	curl_close($ch);
	$xml = new SimpleXMLElement($data);
	$fb = $xml->feed->entry['circulation'];

	$nb = 0;
	foreach($xml->feed->children() as $circ){
		$nb += $circ['circulation'];
	}

	return round($nb/$interval);
}

Once done, you can call the function wherever you want in your theme files. Pass your Feedburner feed id as a parameter:

<?php
$nb = get_average_readers('catswhocode');
echo "I have ".$nb." RSS readers";
?>

Code initially published on Cats Who Blog.

Did you enjoy this article? Give us some link love, and don't forget to bookmark this page on Delicious.

Notes : Join us and read the Guidelines to submit your guest posts.
Subscribe free updates via: RSS Feed | Email | Twitter

Related Articles

{ 13 comments… read them below or add one }

1 Dean Saliba August 10, 2010 at 11:06 am

I think this would be perfect for a blog that has a decent subscriber count. I’ve only got about 16 so it probably would be embarrassing for me. :P

Reply

2 Hieu Martin August 11, 2010 at 6:59 am

Lolz :) ) @Dean Saliba why you embarrassing . try get more Subscriber for yourself

Reply

3 Online Music Clubs August 10, 2010 at 11:14 am

Join one of the best online music clubs today! We offer free newsletters and more!

Reply

4 DEN @ Dreamhost Coupon August 10, 2010 at 11:53 am

I’m never easy with codes but that was clean

Reply

5 Blog Angel a.k.a. Joella August 10, 2010 at 12:59 pm

Now that’s a neat bit of code. Many people are sure to find it interesting and very helpful. Thanks for sharing it.

Reply

6 Hieu Martin August 11, 2010 at 7:00 am

Thanks for your comment. Hope you like this tips

Reply

7 NewGadgetz August 10, 2010 at 8:16 pm

Thanks for this, I was looking for this code to display on a custom theme. Average feed readers are imprtant to establish trust with your users

Reply

8 Hieu Martin August 11, 2010 at 7:01 am

Happy this post can help you do that. Try it for your site now and you will happy ^^

Reply

9 Anup @ Hack Tutors August 11, 2010 at 3:35 am

Nice but, Feedburner is great way to do it :D

Reply

10 Hieu Martin August 11, 2010 at 7:01 am

:) ) hi Anup . Feedburner is number one. i’m use feedburner too

Reply

11 Gadget Guy August 12, 2010 at 8:44 pm

Thanks for the code, I was looking for this for some time to display feedburner on my blog. I saw it first on nettuts

Reply

12 hgoze August 13, 2010 at 7:56 am

Thanks for the code. ++reply

Reply

13 hans ganteng August 17, 2010 at 7:19 pm

thanks for sharing this…;)

Reply

Leave a Comment

Previous post:

Next post: