Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

RSS feed as blog posts


Go to End


3 Posts   1637 Views

Avatar
justjc51

Community Member, 23 Posts

1 October 2008 at 9:01pm

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?

Avatar
Willr

Forum Moderator, 5523 Posts

2 October 2008 at 1:17pm

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

Avatar
justjc51

Community Member, 23 Posts

2 October 2008 at 7:23pm

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