Installing Feedburner Counts For Feedburner RSS
October 21, 2009 · Print This Article
If you look off to the right side of the page, at the RSS subscribe section, you’ll see (well, at the time of this writing anyhow) the count of the number of RSS readers that I currently have.
I had at first tried out the FeedBurnerCount wordpress plugin, but I couldn’t ever get it to register my feed count. So after digging a little deeper, I found examples that were similar to what I needed, but not quite what I was looking for.
What I have below is the culmination of several ideas from many authors, and piled them into one conglomeration that works as of Wordpress 2.8.5.
The first thing I did was to add the following into my functions.php file in my theme:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | require_once(ABSPATH . 'wp-includes/class-snoopy.php'); function feedburner_textcount($arg='') { $fb = get_option("feedburnersubscribecount"); if ($fb['lastcheck'] < ( mktime() - 600 ) ) { $snoopy = new Snoopy; $result = $snoopy->fetch("http://api.feedburner.com/awareness/1.0/GetFeedData?uri=BloggingEmergency"); if ($result) { preg_match('/circulation=\"([0-9]+)\"/',$snoopy->results, $matches); if ($matches[1] != 0) $fb['count'] = $matches[1]; $fb['lastcheck'] = mktime(); update_option("feedburnersubscribecount",$fb); } } if ($arg == '') { echo $fb['count']; } else { return $fb['count']; } } |
On line 1 we include the snoopy class, which is an open source library of functions to access other networks.
Line 3 declares a new function called feedburner_textcount, that takes an optional argument. The argument can be anything you want, and if an argument is used, will return the value to be used in functions, otherwise, it will echo the result out, as is usually needed for HTML output.
This is also the function name that we’ll use in a bit to put the feedcount in place.
The rest of the code is mostly for obtaining the feed count and storing it in the database.
Line 18 is what checks for the input arguments. If an argument was found, it returns the value, otherwise it echos it out (which is what you want most of the time).
Then to display the code in the sidebar, you’ll want to display something like this in sidebar.php:
1 2 3 4 5 6 7 | <div> <p>Become One Of Our</p> <a href="http://feeds2.feedburner.com/BloggingEmergency"> <?php $subs = feedburner_textcount('ret'); echo $subs; ?> </a> <p>Loyal RSS Readers</p> </div> |
I chose to have a return value and echo $subs (the number of subscribers), but you should also be able to do this if you want to:
1 | <?php feedburner_textcount(''); ?> |
That’s really about it. Just create your div for images/text (look at the source of mine as a starting point), and insert your feedburner_textcount() function in the right place, and your subscribers will be listed for the public to see just how popular your blog really is.
Comments
Got something to say?