I would like to be able to generate an rss feed for all of the articles on my site. Is there a way to do this?
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.
Yes, of course :-)
I'd recommend to work through SilverStripe tutorial two, and after that to have a look at SilverStripes RSS documentation .
Hope that helps,
Cheers
Yup I tried that. Not exactly what I had in mind. I am trying to generate an RSS feed of all the articles on the site into one feed.
Got it to work almost the way I want it too, had to adjust a bit of code.
used this in my Page.php file
function init() {
RSSFeed::linkToFeed($this->Link() . "rss", "Hulsey Plumbing and Environmental Services");
parent::init();
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
}
function rss() {
$rss = new RSSFeed($this->LatestUpdates(), $this->Link(), "Hulsey Plumbing and Environmental Services", "Shows a list of the 10 most recently updated pages.", "Title", "Content", "");
$rss->outputToBrowser();
}
function LatestUpdates() {
// 10 is the number of pages
return DataObject::get("Page", "", "Content", "", 100);
}
and this in my HomePage.php file
class HomePage_Controller extends Page_Controller {
function init() {
RSSFeed::linkToFeed($this->Link() . "rss", "Hulsey Plumbing and Environmental Services");
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
}
function rss() {
$rss = new RSSFeed($this->LatestUpdates(), $this->Link(), "Hulsey Plumbing and Environmental Services", "Shows a list of the 10 most recently updated pages.", "Title", "Content", "");
$rss->outputToBrowser();
}
function LatestUpdates() {
// 10 is the number of pages
return DataObject::get("Page", "", "Content", "", 100);
}
}
Notice all i did was change LastEdited DESC to Content and change the article count from 10 to 100 so that it would display all articles on site.
I then changed RSSFeed.ss to this
<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>$Title</title>
<link>$Link</link>
<atom:link href="$Link" rel="self" type="application/rss+xml" />
<description>$Description.XML</description>
<category>Plumbing Services</category>
<% control Entries %>
<item>
<title>$Title.XML</title>
<link>$AbsoluteLink</link>
<% if Description %><description>$Description.LimitCharacters(400)</description><% end_if %>
<% if Date %><pubDate>$Date.Rfc822</pubDate>
<% else %><pubDate>$Created.Rfc822</pubDate><% end_if %>
<% if Author %><dc:creator>$Author.XML</dc:creator><% end_if %>
<guid>$AbsoluteLink</guid>
<category>$MenuTitle</category>
</item>
<% end_control %>
</channel>
</rss>
Notice I changed the Description field to $Description.LimitCharacters(400) to keep the rss from showing the entire contents of every oage, and I also added <category>$MenuTitle</category> so that in IE a menu on the right would appear with links to each article.
What I want tp figure out is instead pf using <category>$MenuTitle</category> I can replace $Menutitle with a different variable that would sort the rss by section, and then children of those sections rather than display a link just to each article.
One problem I am having though, the link that gets generated to view the rss feed has issues when on the home page. if you are at the url http://www.hulseyenvironmental.com and then type /rss after the url, you get a page not found. But if you type in the url http://www.hulseyenvironmental.com/home/rss you get the rss feed page. Is there any way around this?
A simple hack for the homepage rss link
$rssLink = $_SERVER['REQUEST_URI'];
if (($rssLink == "/rss") || ($rssLink == "/rss/")) Director::redirect("home/rss/");
You can replace MenuTitle with any db field of your choice. MenuTitle only works when you are extending SiteTree, if you are extending DataObject then you need to have something like
function getMenuTitle(){
return ($this->MenuTitle ? $this->MenuTitle : $this->YourTitleFieldHere)
}