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.

Customising the CMS /

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

Custom sorting for SiteTree


Go to End


3 Posts   3478 Views

Avatar
tr

Community Member, 4 Posts

11 August 2010 at 8:58pm

Edited: 11/08/2010 9:00pm

Is it possible to change the sort order of certain objects in the SiteTree? There is $default_sort, but when set for own SiteTree objects that one has no effect for the page tree displayed in admin view.

All I got to work was changing the sort order of the whole tree structure by putting

SiteTree::$default_sort = 'Title';

in _config.inc.php. Though I want to sort some objects alphabetically, some by date and some by the default "Sort" field.

Avatar
JL

Community Member, 10 Posts

13 October 2010 at 5:26pm

I have the same requirement too. Currently I am doing this:

SiteTree::$default_sort = 'IF("SiteTree"."ClassName" = \'MyPage\', LOWER("SiteTree"."Title"), "SiteTree"."Sort")';

This will sort MyPage pages using Title and the rest of the pages using Sort. If anyone has a better solution, do share. Thanks

Avatar
DNA

Community Member, 24 Posts

24 November 2010 at 10:43am

Edited: 24/11/2010 10:44am

In case someone else is looking for answers here, i thought i'd add a little work around that I found helpful.

If you want to sort your pages once but still be able to drag and drop pages to change the order:
1) Add the code Timon added
2) Go into the backend.
3) Tick 'Drag and Drop reordering'
4) Change the order of one page, change it back.
5) Publish page.
6) Bingo. Your pages are now sorted by Title or whatever you set it to.
7) Remove Timons code.

Hope that helps someone.