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.

General Questions /

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

Posting RSS Feed on ArticleHolder.ss


Reply


2 Posts   1251 Views

Avatar
Happysadhu

Community Member, 33 Posts

11 August 2009 at 8:20am

Edited: 11/08/2009 1:01pm

Hello,
I would like to post the following pubmed RSS feed on my articleholder page:
http://eutils.ncbi.nlm.nih.gov/entrez/eutils/erss.cgi?rss_guid=1JAk5IMbg5brNNHlJdI8W1KPW9SEh2vqRx6_PmPUwADwffFU05

I've looked at a number of posts on the subject and I'm still confused as there are a number of suggested approaches (some likely outdated). What is considered to be the easiest, most up-to-date way to show a rss feed on any given page (SS version 2.3.2+)?

I came across this post: http://www.silverstripe.org/archive/show/218454#post218454 where Willr suggested the following code (which I added to my ArticleHolder.php file):

function CustomRSSFeed() {
$feed = new SimplePie(URL OF THE RSS FEED);
$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;
}

Using <% control CustomRSSFeed %>$Title<% end_control %> in ArticleHolder.ss.

However, I get the following error: Fatal error: Class 'SimplePie' not found in /Applications/XAMPP/xamppfiles/htdocs/holybasil/mysite/code/ArticleHolder.php on line 27. I put my url in quotes for $feed, without which there was an additional error.

I tried the restfulservice approach as suggested at the bottom of this link.
http://doc.silverstripe.com/doku.php?id=restfulservice#how_to_use_restfulservice_to_easily_embed_an_rss_feed

But just as "Superautomatic" commented in his post at http://silverstripe.org/archive/show/89336#post89336, I can only get the example RSS feed to work not my own (see above for the RSS address). I suspect that it is RSS 1.0 versus RSS 2.0 issue (my RSS address being 2.0). Jam13 offered some code at the bottom of the Superautomatic posting. However, I have no idea how to implement it in a template. He doesn't give an example.

I would appreciate any help,
Sam

Avatar
socks

Community Member, 191 Posts

24 September 2009 at 9:59pm

Edited: 24/09/2009 10:01pm

I just ran into the same issue. That code worked in 2.2.x, but is now broken in 2.3.x.

It's borrowed from the Blog Module (or somewhat similar). Blog > Code > RSSWidget.php

Download the newest version of the Blog Module and grab the updated code and paste into your page. I did so, and it's working fine on my site.