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

List news pages under a newsholder page


Go to End


2246 Views

Avatar
Amir Mostofi

Community Member, 59 Posts

25 August 2009 at 5:09pm

Edited: 25/08/2009 5:12pm

I have defined NewsHolder and NewsPage classes as instructed in the SilverStripe Tuts. Now, I have page 1 of type NewsHolder and subpage 11, subpage 12, ... of type NewsPage under it. I also have page 2 of type NewsHolder and subpage 21, subpage 22, ... of type NewsPage under that. In the sitemap, Page 1 appears above Page 2.

Now, I have defined the following function in NewsHolder.php

function NewsArchive() {
$news = DataObject::get_one("NewsHolder");
return ($news) ? DataObject::get("NewsPage", "ParentID = $news->ID", "Date DESC") : false;
}

In my templates, this function correctly lists the news items under Page 1, but on Page 2, the news list returned is that of Page 1. The function only selects the first instance of NewsHolder in the sitemap. How can I use class NewsHolder for multiple pages and correctly generate the chronological list of NewsPage pages under each NewsHolder page?