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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

RSS Feed


Go to End


5 Posts   2590 Views

Avatar
hulsey

Community Member, 13 Posts

2 August 2011 at 4:47am

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?

Avatar
Invader_Zim

Community Member, 141 Posts

2 August 2011 at 4:58am

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

Avatar
hulsey

Community Member, 13 Posts

3 August 2011 at 2:40am

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.

Avatar
hulsey

Community Member, 13 Posts

4 August 2011 at 8:09am

Edited: 04/08/2011 8:16am

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?

Avatar
patjnr

Community Member, 102 Posts

9 August 2011 at 1:19am

Edited: 09/08/2011 1:20am

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)
	}