phpatom-feedsimplepie

load all items from one Atom RSS feed


I'm using SimplePie and it gives me a headache. First, let me explain what I'm trying to do. My friend, for which I'm making a website, already has blog with not so few posts and I want to load all items from there, parse them and display them if the label is correct. The problem begins when the SimplePie doesn't load the entire feed but limits to 25. According to this SO question, the default limit is 10 and I also checked the feed with Google Chrome extension where I got the entire blog content. And to clarify, the items are not cached (OK, actually they are) but are still live on the blog, so they weren't removed and I'm not getting an old content. Also, I downloaded the feed url and opened it in notepad, in there are 25 items.

Here is my example of the init() code:

 require_once("php/autoloader.php");
 $feed=new SimplePie();
 $feed->set_feed_url("http://jadran303.blogspot.com/feeds/posts/default");
 $feed->enable_cache(false);
 $feed->init();
 $feed->handle_content_type();

and here is my code to test the results and to see what I'm getting (this is not the production version):

$i=1;$j=1;$k=1;
foreach($feed->get_items() as $item):
 echo$k." ".$item->get_title()." - ".$item->get_date('j F Y, g:i a')."<br />";
 if($category=$item->get_category()){
  echo$j". ".$item->get_title()." - ".$category->get_label()." - ".$category->get_term()."<br />";
  if($category->get_label()=="Peugeot 406 Coupé na terenu"){
   echo" - $i ".$item->get_title()."<br />";
   $i++;
  }
  print_r($category);
  $j++;
 }
 $k++;
endforeach;

My questions:

Thank you for your help.


Solution

  • Also, I downloaded the feed url and opened it in notepad, in there are 25 items.

    That's why SimplePie can't load any more items; there aren't any being given there. SimplePie (or any other parser) can only get what's in the feed.

    If you want more items, you can try using Google's feed APIs (they use cached data from Google Reader, so they should have every item). (The other answer is actually incorrect, as it's not limited to 10 items; that's just in the NewsBlocks example code.) Alternatively, dig around on the site and see if you can find a way to paginate the feed.

    As per your comment below, you should be able to append ?max-results=1000 to any Blogger feed to get 1000 items instead. This is specific to Blogger, but most sites have something similar.