Hey folks,
wondering if there was a simple way to parse RSS feeds on my homepage for an external blog. I need to use an external websites RSS for the news section of my SS site. For example it would list the last 5 posts from the blog. I looked at the RSS Widget but it looked like that was strictly for the blog (maybe)? Can this widget be used for standard ss pages? If so how? Please note that I am a newb in the world of SS.
Thanks!
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.
yep you can. Well you dont need to use the widget, you could just copy how the widget does it in your own homepage.
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;
}
I think might work in 2.2.2. If your template you would do <% control CustomRSSFeed %>$Title<% end_control %>
Wasn't working so I looked under the hood and see that I am running 2.2.1. Now debating whether to upgrade or to see if there is an easy work-around for this version.. suggestions?
thanks for all your help!
uh oh. Error message. not sure if its because i tinkered with your code or anther reason but on rebuild of the db the i get an error towards the bottom of the build list. help!
<code>Group_Unsecure
Member
Member_UnsubscribeRecord
Permission
Widget
WidgetArea
ERROR:
Error
The website server has not been able to respond to your request</code>
ERROR:
Error
The website server has not been able to respond to your request
is the standard error page. Turn on more useful error messaging by putting the site in dev mode. Add this to your mysite/_config.php file - Director::set_environment_type("dev"); This will output a proper error.
hmmmmmm. Don't think it was the config file but the server is completely not responding now. I have a feeling i mucked up the db. Is there such a thing as the constant loading white screen of death?
I resolved all other problems and can get bakc to my RSS problem now...
I think my last question to you was whether your code would work in 2.2.1? I did a search and SimplePie is definately built into the core in some respect. Not sure if it's just for the blog widget though.