How To Display The Average Number Of Your Subscribers

a minute read

Many bloggers use Feedburner to display the number of their subscribers. If you want to be able to show the average number of them over the past 7 days, here is the code that is useful for this purpose.
As usual, first of all you need to insert this function into the functions.php file of your theme:

1 function get_average_readers($feed_id,$interval = 7){
2     $today date('Y-m-d'strtotime("now"));
3     $ago date('Y-m-d'strtotime("-".$interval." days"));
4     $feed_url="".$feed_id."&dates=".$ago.",".$today;
5     $ch = curl_init();
6     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
7     curl_setopt($ch, CURLOPT_URL, $feed_url);
8     $data = curl_exec($ch);
9     curl_close($ch);
10     $xml new SimpleXMLElement($data);
11     $fb $xml->feed->entry['circulation'];
13     $nb = 0;
14     foreach($xml->feed->children() as $circ){
15         $nb += $circ['circulation'];
16     }
18     return round($nb/$interval);
19 }

Further, you can call this function anywhere on the site, but for this you need to specify id Feedburner as a parameter:

1 <?php
2 $nb = get_average_readers('wpincode');
3 echo "I have ".$nb." RSS subscribers";
4 ?>


Facebook Twitter LinkedIn Telegram Pocket

Related Posts:

Have you ever had a need to bring your fresh posts from each separate column to your WordPress sidebar? Recently, one of our users asked us if there was a way to quickly bring up fresh posts from a specific category to the WordPress sidebar widget. In today’s ...
If the content on your site is correctly organized by headings, then you probably will not need the block “Similar entries” on the site, because you can simply display fresh entries from the same heading. In today’s article, we will show you how to create a se...
Recently, one of our users asked how to display a list of child pages for a page in WordPress. Often in the work on a site where there are child pages, you may need to show a list of these very child pages in the sidebar widget or anywhere else in the template...