Jump to:

23480 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » RSS Feed

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

Page: 1
Go to End
Author Topic: 1091 Views
  • hulsey
    Avatar
    Community Member
    13 Posts

    RSS Feed Link to this post

    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?

  • Invader_Zim
    Avatar
    Community Member
    141 Posts

    Re: RSS Feed Link to this post

    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

  • hulsey
    Avatar
    Community Member
    13 Posts

    Re: RSS Feed Link to this post

    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.

  • hulsey
    Avatar
    Community Member
    13 Posts

    Re: RSS Feed Link to this post

    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?

  • patjnr
    Avatar
    Community Member
    101 Posts

    Re: RSS Feed Link to this post

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

    1091 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.