21298 Posts in 5735 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 996 Views |
-
Displaying external RSS feed on page

15 February 2011 at 8:43pm
Hi there,
I am trying to display one external RSS feed on a site homepage. I have looked around a fair bit and thread http://silverstripe.org/customising-the-cms/show/11548 is a convoluted way of doing it, with formatting problems and the "=" in links in the feed text become "%" when you click through so they don't work.
So is there an easier way of doing this? I just want to display one external RSS feed in a small window on the home page.
Cheers
-
Re: Displaying external RSS feed on page

15 February 2011 at 10:47pm
I am sure there is a better way, but I've used simplepie for this in the past...
<?php
class RSSJobsPage extends Page {}
class RSSJobsPage_Controller extends Page_Controller {
function RSSJobsPage(){
$output = new DataObjectSet();
$feed = new SimplePie('http://www.silverstripe.org/blog/rss', TEMP_FOLDER);
$feed->init();
if($items = $feed->get_items(0, 10)){
foreach($items as $item){
// Cast the Date
$date = new Date('Date');
$date->setValue($item->get_date());// Cast the Title
$title = new Text('Title');
$title->setValue($item->get_title());// Cast the description and strip
$desc = new Text('Description');
$desc->setValue(strip_tags($item->get_description()));
$output->push(new ArrayData(array(
'Title' => $title,
'Date' => $date,
'Link' => $item->get_link(),
'Description' => $desc
)));
}
}return $output;
}
}attached is the source code for simple pie....
-
Re: Displaying external RSS feed on page

1 March 2011 at 2:41pm
Thanks Swaiba, sorry for the delay.
I'm pretty new to php and the SS setup I'm afraid - would I put this code as a php file in mysite/code? I'd like the external feed to appear on the homepage, so it would be called in that template - how would I call the feed from the homepage.ss template?
Also where would I need to put the SimplePie php file?
Cheers
-
Re: Displaying external RSS feed on page

10 December 2011 at 3:26am
I'm not sure the advantage of using the SimplePie.php file. I found that if I add in the following line to the code example it works:
include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.inc'));
<?php
class RSSJobsPage extends Page {}
class RSSJobsPage_Controller extends Page_Controller {
function RSSJobsPage(){include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.inc'));
$output = new DataObjectSet();
$feed = new SimplePie('http://www.silverstripe.org/blog/rss', TEMP_FOLDER);
$feed->init();
if($items = $feed->get_items(0, 10)){
foreach($items as $item){
// Cast the Date
$date = new Date('Date');
$date->setValue($item->get_date());// Cast the Title
$title = new Text('Title');
$title->setValue($item->get_title());// Cast the description and strip
$desc = new Text('Description');
$desc->setValue(strip_tags($item->get_description()));
$output->push(new ArrayData(array(
'Title' => $title,
'Date' => $date,
'Link' => $item->get_link(),
'Description' => $desc
)));
}
}return $output;
}
}
| 996 Views | ||
|
Page:
1
|
Go to Top |



