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 = "https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=" . $feed_id . "&dates=" . $ago . "," . $today ; |
6 |
curl_setopt( $ch , CURLOPT_RETURNTRANSFER, 1); |
7 |
curl_setopt( $ch , CURLOPT_URL, $feed_url ); |
8 |
$data = curl_exec( $ch ); |
10 |
$xml = new SimpleXMLElement( $data ); |
11 |
$fb = $xml ->feed->entry[ 'circulation' ]; |
14 |
foreach ( $xml ->feed->children() as $circ ){ |
15 |
$nb += $circ [ 'circulation' ]; |
18 |
return round ( $nb / $interval ); |
Further, you can call this function anywhere on the site, but for this you need to specify id Feedburner as a parameter:
2 |
$nb = get_average_readers( 'wpincode' ); |
3 |
echo "I have " . $nb . " RSS subscribers" ; |