Jump to:

23480 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Pulling RSS feeds from other sites onto my home page.

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3 4
Go to End
Author Topic: 4927 Views
  • zim
    Avatar
    Community Member
    135 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    i get this error when i use the simplepie class

    Fatal error: Class 'SimplePie' not found in C:\wamp\www\SilverStripe01\mysite\code\HomePage.php on line 67

    i am using this
    function CustomRSSFeed() {
       $feed = new SimplePie("http://feeds.guardian.co.uk/theguardian/world/rss");
       $feed->feed->init();
       $output = new DataObjectSet();
       if($items = $feed->feed->get_items(0, 10)){
          foreach($items as $item){
             $output->push(new ArrayData(array(
                "Title" => $item->get_title(),
                "Link" => $item->get_link()
             )));
          }
       }
          return $output;
    }

    and

    <% control CustomRSSFeed %>
          
    $Title
          
    <% end_control %>

  • D-L
    Avatar
    Community Member
    13 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    Regarding your API key dilemma, Google allows you to simply put in localhost as your domain. This will allow you to generate and use an API key for your local WAMP or MAMP installation.

  • D-L
    Avatar
    Community Member
    13 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    Zim zimma - About your fatal error.... It seems you are using WAMP, so all you need to do is enable curl. click on the wamp icon, an you can enable curl in the PHP extensions. Hope this helps, dude.

  • D-L
    Avatar
    Community Member
    13 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    Mate...there is also a widget that pulls in news from CNN; I've not personally used it, but looks to me like it could be made to do what you need it to with a little modification to pull in just a single title from CNN, a single title from another news site, and so on...

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    You appear to be missing the line in your method to include SimplePie. It is not included as a default silverstripe library.

    Add this:

    include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));

    To the first line of your method.

    Mo

  • zim
    Avatar
    Community Member
    135 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    Hey Mo,

    do you mean like the below... because that made the whole site not display? am I putting the
    include in the right place? Thanks for help dude.

    function CustomRSSFeed() {

    include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));

       $feed = new SimplePie("http://feeds.guardian.co.uk/theguardian/world/rss");
       $feed->feed->init();
       $output = new DataObjectSet();
       if($items = $feed->feed->get_items(0, 10)){
          foreach($items as $item){
             $output->push(new ArrayData(array(
                "Title" => $item->get_title(),
                "Link" => $item->get_link()
             )));
          }
       }
          return $output;
    }

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    Hmm, there are a couple of what look like errors, the biggest one is that you have used $feed->feed->methodname, it should just be $feed->methodname.

    Try this:

    function CustomRSSFeed() {

       include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php'));
       
       $feed = new SimplePie("http://feeds.guardian.co.uk/theguardian/world/rss", TEMP_FOLDER);
       $feed->init();
       
       $output = new DataObjectSet();
       if($items = $feed->get_items(0, 10)){
          foreach($items as $item){
             // Cast the Title to get rid of nasty things
             $title = new Text('Title');
             $title->setValue($item->get_title());
             
             $output->push(new ArrayData(array(
                "Title" => $title,
                "Link" => $item->get_link()
             )));
          }
       }
       return $output;
    }

    Mo

  • zim
    Avatar
    Community Member
    135 Posts

    Re: Pulling RSS feeds from other sites onto my home page. Link to this post

    Hey Mo,

    Thanks dude! That worked. Just what I need.

    How would I go about pulling feed from multiple sites. Say BBC, YAHOO, google news etc. as well as just guardian.

    Really appreciate your help. I know I need to learn my php!

    4927 Views
Page: 1 2 3 4
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.