SimplePie v1.2 & Google News Feed

Feed $items from http://news.google.com/ produce a permalink that, when clicked, do not go directly to its respective news source.  Rather, a ‘Google Redirect Notice’ page appears with a direct link to the source.  You can read more about the notice here: Google Redirect Notice.

You can use PHP substr to return only a portion of a resulting permalink; namely, the direct link without the following:

Here is the sample code from the SimplePie documentation with the change (highlighted):

<?php
/*
Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
*/
foreach ($feed->get_items() as $item):
?>

<div class="item">
<h2><a href="<?php echo substr($item->get_permalink(), 54, -43); ?>"><?php echo $item->get_title(); ?></a></h2>
<p><?php echo $item->get_description(); ?></p>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>

<?php endforeach; ?>

This is only a quick fix that will break should the aforementioned permalink structure change.  For this reason, refer to the SimplePie get_permalink() documentation for more information.

 

Posted in response to: “Google Redirect Notice”

Advertisements

Tags:

One Response to “SimplePie v1.2 & Google News Feed”

  1. Kramer Phillips Says:

    Marshall,

    Great post. I am wondering if you have had problems with retrieving feeds from google news using simplepie. If you a copy of your script that you would be willing to send me, or advice I’d greatly appreciate it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: