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.

Data Model Questions /

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

[SOLVED] Inverted sorting of children


Go to End


3 Posts   2259 Views

Avatar
stevenlangbroek

Community Member, 3 Posts

28 November 2009 at 1:45am

Edited: 02/12/2009 12:48am

I've built a basic site, and have extended it somewhat. I now have the ArticleHolder and ArticlePage-children. However, I want to sort them in inverted order (in relation to the sitetree). So uhmm... do i place a statement in the control children, in the ArticleHolder or ArticlePage? I don't get it... (yes it's a noob question, I know... I'm learning)

Avatar
Willr

Forum Moderator, 5523 Posts

28 November 2009 at 9:29pm

You will need to add a custom function to your ArticleHolder which calls sort() on the children.

function OrderedChildren() {
$oc = $this->Children(); 
$oc->sort('Sort DESC'); 
return $oc;
}

Then instead of using <% control Children %> you can use <% control OrderedChildren %>

Avatar
stevenlangbroek

Community Member, 3 Posts

28 November 2009 at 11:58pm

Wow... it's that easy huh? Thanks for being so helpful, I'm on plenty of forums and questions with such obvious answers usually get flamed to bits, so props where props are due! :)