Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » RSS feed as blog posts

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1182 Views
  • justjc51
    Avatar
    Community Member
    23 Posts

    RSS feed as blog posts Link to this post

    I know there is a widget that posts RSS results in a side menu, so SilverStripe is clearly able to handle them, what I want however is for the RSS results to show up as a new blog post. is that possible?
    And could anyone give me some pointers on how it's done?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: RSS feed as blog posts Link to this post

    I assume that the RSS feed comes from an external source and you want to create posts with them.. I did the same with my twitter feed. Got the feed data, and made objects from them so that I could sort / search all of them. Heres an outline of my code. You will need to put this somewhere eg Page.php -> Page_Controller

       $feed = new RestfulService("URL OF RSS FEED");
       $conn = $feed->connect('');
       $msgs = $feed->getValues($conn, "status");
             
       $output = new DataObjectSet();
       foreach($msgs as $msg){
          foreach($feed as $feedItem) {
             $blog = new Blog_Entry();
             $blog->Title = "This is the Title"; // should come from $feedItem
             $blog->setDate(date("Y-m-d H:i:s",time()));
             $blog->publish("Stage", "Live");
             $blog->Author = "Author";
             $blog->Content = $feedItem->Content;
             $blog->ParentID = DataObject::get_one('BlogHolder')->ID;
             $blog->write();
          }
       }

    Thats the outline at least. This will do things like create the blog entry every time you look at the feed url (which is probably not wise) but thats how it would work

  • justjc51
    Avatar
    Community Member
    23 Posts

    Re: RSS feed as blog posts Link to this post

    Thanks for your help willr, at least now I have something to work with

    1182 Views
Page: 1
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.