Hi.. On my site I have a number of feeds (one per wordpress category), each one is burned with Feedburner, and has the option to subscribe by email. Is there a way I can combine the number of subscribers and then display the total on my site? Similar to the feedburner chicklet (though in plain text). For Example: Feed 1 - 20 subscribers Feed 2 - 80 subscribers Feed 3 - 45 subscribers Feed 4 - 200 subscribers - combine feeds and display total on homepage - "We have 345 Subscribers" ...that sort of thing? I have already combined my feeds into one using Yahoo Pipes and then burned that new combined feed too, but im not sure if subscription stats will add up in the way im hoping? Anyone have any thoughts or ideas on this? Thank you
Use the Feedburner Awareness API. Create a function that cURL's the XML and extracts the circulation number. Then have a loop that goes over every wordpress category and fires that function - sum up the total. Done.
Hi, thanks for your reply. Im still trying to learn a bit of javascipt and ive no idea how to use an API or write something like that. Could you help at all? Id be willing to make a little donation or something for you via PayPal for your time? Many thanks, Phil
wow, thank you so much for the link. why is it these types of site never crop up when you spend hours searching something! I'll post back to let you know how it goes, fingers crossed! Thanks again.
Doesnt that link just display the Subscribers (and the change in % terms) for one single feed through? I cant see anything about it combining multiple feeds to display the subscribers in total?
Yes, it only finds the number of subscribers for one feed. So you would call it n number of times. What are your feed URLs? I'll post you an example.
Hi, thank you for offering to help, my feed URLs are: http://feeds.feedburner.com/renownestates http://feeds.feedburner.com/renownforsale http://feeds.feedburner.com/forsale/apartments http://feeds.feedburner.com/forsale/bungalows http://feeds.feedburner.com/forsale/detached http://feeds.feedburner.com/forsale/flats http://feeds.feedburner.com/forsale/semi http://feeds.feedburner.com/forsale/studios http://feeds.feedburner.com/forsale/terraces There may be more to add later, but im sure when I know how it works I could add these.
Something like this should do it. You should also take a look at caching scripts in PHP - making 9+ HTTP requests every time a visitor hits your site will slow things down. You would want to only do it every hour or so. <?php // Your feeds $feeds[] = 'http://feeds.feedburner.com/renownestates'; $feeds[] = 'http://feeds.feedburner.com/renownforsale'; $feeds[] = 'http://feeds.feedburner.com/forsale/apartments'; $feeds[] = 'http://feeds.feedburner.com/forsale/bungalows'; $feeds[] = 'http://feeds.feedburner.com/forsale/detached'; $feeds[] = 'http://feeds.feedburner.com/forsale/flats'; $feeds[] = 'http://feeds.feedburner.com/forsale/semi'; $feeds[] = 'http://feeds.feedburner.com/forsale/studios'; $feeds[] = 'http://feeds.feedburner.com/forsale/terraces'; $sum_subscribers = 0; foreach ($feeds as $feed) $sum_subscribers += GetFeedburnerSubscribers($feed); // display results echo $sum_subscribers; // the function that retrieves the number of subscribers function GetFeedburnerSubscribers($feed_uri) { $feed_url = 'http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=' . urlencode($feed_uri); $feed_xml = new SimpleXMLElement(file_get_contents($feed_url)); return $feed_xml->feed->entry->attributes()->circulation; } ?> PHP:
Hi, I've tried that out, and although im not able to test it fully yet (due to a severe lack of subscribers at the moment lol) it does appear to be working! I'll change the feeds around later and test it properly. How can I set it to only refresh or update the number of subscribers, say once every 24 hours? I dont want to slow the site down because of it, as it is just a stat at the end of the day.So would 24 hours help much with the speed of things do you think? There may be up to 25 feeds in total eventually, so do you think 24 hours would be okay for every refresh?
This script does the same thing, but it has inbuilt caching. It will only update the number of subscribers if they haven't been updated in the past 24 hours. Once the result is cached, this runs a lot faster. (just click reload and see how fast it shows up) <?php // the filename of the cache $cacheFile = 'feedSubscribers.txt'; // Your feeds $feeds[] = 'http://feeds.feedburner.com/renownestates'; $feeds[] = 'http://feeds.feedburner.com/renownforsale'; $feeds[] = 'http://feeds.feedburner.com/forsale/apartments'; $feeds[] = 'http://feeds.feedburner.com/forsale/bungalows'; $feeds[] = 'http://feeds.feedburner.com/forsale/detached'; $feeds[] = 'http://feeds.feedburner.com/forsale/flats'; $feeds[] = 'http://feeds.feedburner.com/forsale/semi'; $feeds[] = 'http://feeds.feedburner.com/forsale/studios'; $feeds[] = 'http://feeds.feedburner.com/forsale/terraces'; // start output buffering ob_start(); // retrieve the cache if it's less than 24 hours old $output = retrieveCache($cacheFile, 60 * 60 * 24); // cache doesn't exist or is too old if ($output === false) { $sum_subscribers = 0; foreach ($feeds as $feed) $sum_subscribers += GetFeedburnerSubscribers($feed); echo $sum_subscribers; $output = ob_get_contents(); generateCache($output, $cacheFile); } // end output buffering ob_end_clean(); // output number of subscribers echo $output; // the function that retrieves the number of subscribers function GetFeedburnerSubscribers($feed_uri) { $feed_url = 'http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=' . urlencode($feed_uri); $feed_xml = new SimpleXMLElement(file_get_contents($feed_url)); return $feed_xml->feed->entry->attributes()->circulation; } // retrieves a cache file, or returns false if it doesn't exist function retrieveCache($file, $expiry) { if (file_exists($file) && filemtime($file) > (time() - $expiry)) return file_get_contents($file); return false; } // generates a cache file function generateCache($content, $file) { $fp = fopen($file, 'w'); if (!$fp) die('Failed to open cache for writing, check permissions.'); fwrite($fp, $content); fclose($fp); } ?> PHP:
Hi, wow, that really does make a speed difference after first load! - Would you recommend including the script directly into the page, or importing it from an external file via an includes? (Also is there anyway I can set this to load last of all, once the rest of the page has loaded?) Thank you so so much for all your help. I really appreciate it, genuinely!
You can call this however you want, embedded or via an include. The only way I can think of making it load last is by loading it from the page via Ajax - so all the HTML/CSS/Images load and then finally the Javascript is run (which calls the PHP script and updates a HTML element).