Feedburner Text Counter To Google FeedProxy In WordPress

January 11th, 2009 by under Blog, Tips

I am using Feedburner counter with text in most of my WordPress themes. Recently, I found that they are not working properly due to the conversion of Feedburner to Google FeedProxy. Today, I found a solution thanks to one of my theme user. I will show you how to do that.

I am using Feedburner counter with text in most of my WordPress themes. Recently, I found that they are not working properly due to the conversion of Feedburner to Google FeedProxy. Today, I found a solution thanks to one of my theme user. I will show you how to do that. I will use the feed.php in my premium theme – Our Community. If you are still using Feedburner service, then you can ignore this tutorial. This is just for those who are using Google FeedProxy.

The Existing Feed File.

<?php
	$last_update = intval(get_option('feed_lastupdate'));
	$now = time();
	if(($now - $last_update) > (60*60*24)) :
		//get cool feedburner count
		$feed = get_option('feed');
		$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=$feed";
		
		//Initialize the Curl session
		$ch = curl_init();
		
		//Set curl to return the data instead of printing it to the browser.
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		//Set the URL
		curl_setopt($ch, CURLOPT_URL, $whaturl);
		//Execute the fetch
		$data = curl_exec($ch);
		//Close the connection
		curl_close($ch);
	
		$xml = new SimpleXMLElement($data);
		$fb = $xml->feed->entry['circulation'];
		if(!$fb) :
			$fb = 0;
		endif;
		update_option("feed_count", $fb."");
		//end get cool feedburner count
	
	
		update_option("feed_lastupdate", $now."");
	endif;
	
	$feed_uri = get_option('feed');
	if(!$feed_uri or $feed_uri == '') :
		$feed_uri = get_bloginfo('rss2_url');
	else :
		$feed_uri = 'http://feeds.feedburner.com/' . $feed_uri;
	endif;
?>

<a href="<?php echo $feed_uri; ?>" title="Feed Subscriber Count"><?php echo get_option("feed_count");?></a>

Editing

Change this:

$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=$feed";

Into This:

$whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=$feed";

And this:

$feed_uri = 'http://feeds.feedburner.com/' . $feed_uri;

Into This:

$feed_uri = 'http://feedproxy.google.com/' . $feed_uri;

Full Code:

<?php
	$last_update = intval(get_option('feed_lastupdate'));
	$now = time();
	if(($now - $last_update) > (60*60*24)) :
		//get cool feedburner count
		$feed = get_option('feed');
		$whaturl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=$feed";
		
		//Initialize the Curl session
		$ch = curl_init();
		
		//Set curl to return the data instead of printing it to the browser.
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		//Set the URL
		curl_setopt($ch, CURLOPT_URL, $whaturl);
		//Execute the fetch
		$data = curl_exec($ch);
		//Close the connection
		curl_close($ch);
	
		$xml = new SimpleXMLElement($data);
		$fb = $xml->feed->entry['circulation'];
		if(!$fb) :
			$fb = 0;
		endif;
		update_option("feed_count", $fb."");
		//end get cool feedburner count
	
	
		update_option("feed_lastupdate", $now."");
	endif;
	
	$feed_uri = get_option('feed');
	if(!$feed_uri or $feed_uri == '') :
		$feed_uri = get_bloginfo('rss2_url');
	else :
		$feed_uri = 'http://feedproxy.google.com/' . $feed_uri;
	endif;
?>

<a href="<?php echo $feed_uri; ?>" title="Feed Subscriber Count"><?php echo get_option("feed_count");?></a>

Find out more in archives or subscribe rss feed for future updates.

Sponsor:

15 Comments | RSS 2.0 | Trackback Add comment
From old to new:
  1. hakan yamanoglu February 4th, 2009
  2. kailoon February 9th, 2009
  3. Posizionamento su google June 23rd, 2009
  4. Chris July 9th, 2009
  5. kailoon July 9th, 2009
  6. Text marketing July 27th, 2009
  7. casper @mymoneyblog.info September 27th, 2009
  8. onetarek March 5th, 2010