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.

Template Questions /

[solved] sort all subpages by date(subpages seperated in 2 categories on one site)


Reply


5 Posts   665 Views

Avatar
benni91

Community Member, 72 Posts

26 August 2011 at 8:31am

Hi,
if got this site construction

ReferencesPage.php - http://pastie.org/2429726
ReferencePage.php - http://pastie.org/2429729
ReferencesPage.ss - http://pastie.org/2429730

It looks like this http://www.jaypac.de/image.php?file=736847 and this http://www.jaypac.de/image.php?file=828600

The References are seperated in New and Old ones. But not sorted by Date. Cause i don't know how :/

I want that all the New References are sorted by date. latest ones at first. and the same with the old refernces.

Can someone tell me how?

Thx Benni

Avatar
martimiz

Forum Moderator, 1098 Posts

26 August 2011 at 11:23pm

I'm not quite sure about this - links to a page that has <scr + ipt links and a somewhat erotic popup, but don't seem to make the question any clearer?

Still - since you're not a new member, maybe we should give you a change to explain?

Avatar
benni91

Community Member, 72 Posts

27 August 2011 at 7:34am

Edited: 27/08/2011 7:37am

hmm perhaps it's a little bit clearer if you visit the site

http://hobedesign.de/referenzen/
E-Mail: silverstripe
Password: ss123

there you can see that the references are seperated into new and old. but they aren't sorted by date, they are shown in the order i created them. and i don't know how to sort the new ones and the old ones.

do you know now what i mean?

benni

Avatar
martimiz

Forum Moderator, 1098 Posts

27 August 2011 at 9:29pm

Edited: 27/08/2011 9:30pm

OK, I get it :-)

I wasn't sure if they were your pages the links referred to, so especially with the popup and all, they did look somewhat spammish. You might want to remove these links from your earlier post...

As for your question: I would create a custom function getReferences() in your ReferencesPage_controller, that retreives the ReferencePages in the correct order. Then use <% control References %> instead of <% control Children %> in your template.

You can then sort them by Date descending. Something like (simplest version thinkable):

public function getReferences() {
   return DataObject::get('ReferencePage', "ParentID = '$this->ID'", 'Date DESC');
}

Avatar
benni91

Community Member, 72 Posts

28 August 2011 at 7:49am

Thanks! :)

I tried this function before too. but i made one mistake, i put it after <% control children %>, damn! :D

now it works fine.