I'm trying to create pages on my site which display RSS google blogger posts. I'm using PHP, CodeIgniter, and SimplePie to parse the Google feeds.
Issue 1:
I want to be able to create a link using the guid on one page and then display the invidual blog post on the next page. So I have something like this:
This doesn't work as the guid is not valid for urls and looks a mess (could use url_encode but don't want to). I wanted to get it like this:
http://mysite.co.uk/technology/blog_post/6168323340908483477/1651486241197422269
To do this I need to understand the format of the guid. Is this a json object? If so how do I go about splitting this? I can use explode() to split it but I imagine there's a better way of doing it.
Issue 2:
I can display the feeds on my CodeIgniter / SimplePie site just fine but I can't display an individual feed easily. Here is my code at the moment (untested):
foreach($feeds as $k => $item):
if( $item->get_id()==$this->uri->segment(3) ): //Does id of post match id passed in?
?>
<h1 id="main-heading"><?=$page_title?></h1>
<div class="blog-date"><?=$item->get_date()?></div>
<h3><a href="<?=$item->get_link()?>"><?=$item->get_title()?></a></h3>
<div class="blog-desc"><?=$item->get_description()?></div>
<?
break;//End as we only want to display one post, need a better way of doing this.
endif;
endforeach;
Obviously this is a loop and not an individual reference to 1 feed.
You shouldn't rely on the GUID being a certain format, nor should you rely on it being a valid URL (unless the isPermalink
attribute is set to true
- omitted is supposed to imply true
, but that's not always the case).
Your best bet is to simply hash the GUID. If you want SimplePie to do that for you, just use $item->get_id(true)
If you're only trying to use one feed, then you should only be passing that one into SimplePie, rather than using the multifeeds technique. (It's possible in the future that we'll introduce a SimplePie_Feed
class separate to SimplePie
, allowing you to loop over each feed individually, but this doesn't yet exist.)