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.

Archive /

Our old forums are still available as a read-only archive.

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

RSS feed


Go to End


4 Posts   1750 Views

Avatar
carenas1

Community Member, 3 Posts

15 June 2008 at 3:25pm

Hello,
Could anyone help me?
I have rss feed for my website but it is showing 10 full articles. I need, that in RSS feed would be shown only 10 titles of articles and only first paragraph of article. Please write the code, it would be great!

Avatar
Willr

Forum Moderator, 5523 Posts

15 June 2008 at 4:04pm

When you create a RSS feed you do something like this... (taken from the blog module)

$rss = new RSSFeed($children, $this->Link(), $project . " blog", "", "Title", "ParsedContent");

The last argument in that list points to a method on BlogEntry which produces the content. So say you want the RSS Feed to show the first paragraph you could change that new RSS Feed to something like...

$rss = new RSSFeed($children, $this->Link(), $project . " blog", "", "Title", "MyShortContent");

Then on whatever Page type you are making the RSS feed of (for example a RSS feed of latest NewsPages) you would open up the NewsPages.php file and write a MyShortContent Method in the main class - not the controller that goes something like

function MyShortContent() {
return $this->Content->FirstParagraph();
}

Which will return the first paragraph of text from Content. Hopefully something like that will work for you!

Avatar
carenas1

Community Member, 3 Posts

15 June 2008 at 6:09pm

I can't understand...
I have page.php in which is rss feed.

The page.php source:
<?php

class Page extends SiteTree {
static $db = array(
'Date' => 'Date',
'Author' => 'Text'
);

static $has_one = array(
);

static $icon = "themes/treeicons/news";
}

class Page_Controller extends ContentController {
function project() {
global $project;
return $project;
}

function init() {
RSSFeed::linkToFeed($this->Link() . "rss", "e-sviesa.lt - informacinis portalas");
parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}

function rss() {
$rss = new RSSFeed($this->Latest(), $this->Link(), "e-sviesa.lt - informacinis portalas", "e-sviesa.lt - informacinis portalas", "Title", "Content" , "Author");
$rss->outputToBrowser();
}

function Latest() {
return DataObject::get("Page", "", "Created DESC", "", 10);
}

}

?>

And I need that latest articles would be only from title and first paragraph of article...

Avatar
Willr

Forum Moderator, 5523 Posts

15 June 2008 at 6:34pm

Sorry, my idea didnt even work when I tried it :( should stop coding off the top of my head!