This document contains information for an outdated version (2.3) and may not be maintained any more.

If some of your projects still use this version, consider upgrading as soon as possible.

RSS Feed

Introduction

Generating RSS/Atom-feeds is just a matter of rendering a DataObject and the Page Comment Interface. Handled through the RSSFeed class.

RSSFeed doesn't limit you to generating "article-based" feeds, it is just as easy to create a feed of your current staff-members. The only logical limitation here is that every item in the RSS-feed should be accessible through a URL on your website, so its advisable to just create feeds from subclasses of SiteTree.

Usage

Showing latest Blog posts

  • The first part will add an appropriate link tag for autodetecting RSS feeds
  • The second part sets up /this-page/rss to return the RSS feed. This one returns the children of the current page.
    function init() {
        RSSFeed::linkToFeed($this->Link() . "rss", "RSS feed of this blog");
        parent::init();
    }
    function rss() {
        $rss = new RSSFeed($this->Children(), $this->Link(), "My feed", "This is an example feed.", "Title", "Content", "Author");
        $rss->outputToBrowser();
    }

Example of showing the 10 most recently updated pages

You can use RSSFeed to easily create a feed showing your latest Page updates. Just change mysite/code/Page.php to something like this:

<?php
class Page extends SiteTree {
    static $db = array(
    );
    static $has_one = array(
   );
}
class Page_Controller extends ContentController {
    function init() {
        RSSFeed::linkToFeed($this->Link() . "rss", "10 Most Recently Updated Pages");
        parent::init();
    }
    function rss() {
        $rss = new RSSFeed($this->LatestUpdates(), $this->Link(), "10 Most Recently Updated Pages", "Shows a list of the 10 most recently updated pages.", "Title", "Content", "Author");
        $rss->outputToBrowser();
    }
    function LatestUpdates() {
        // 10 is the number of pages
        return DataObject::get("Page", "", "LastEdited DESC", "", 10);
    } 
}
?>

Viewing Comment RSS Feeds

You can view RSS feeds for comments for a certain page or for all comments on your site by visiting http://www.yoursite.com/PageComment/rss . That produces a RSS Feed of the most recent comments to all of your site. You can also do http://www.yoursite.com/PageComment/rss?pageid=46 where pageid is the id of the page you want to follow

External Sources

RSSFeed only creates feeds from your own data. We've included the SimplePie RSS-parser for accessing feeds from external sources.

API Documentation

RSSFeed

Comments

Comment policy: Please use comments for tips and corrections about the described functionality.
Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant. Use the Silverstripe Forum to ask questions.

blog comments powered by Disqus