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.

Customising the CMS

Custom sorting for SiteTree


3 Posts   1810 Views


11 August 2010 at 8:58pm (Last edited: 11 August 2010 9:00pm), Community Member, 4 Posts

Is it possible to change the sort order of certain objects in the SiteTree? There is [url=$default_sort]$default_sort[/url], 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 Though I want to sort some objects alphabetically, some by date and some by the default "Sort" field.


13 October 2010 at 5:26pm Community Member, 10 Posts

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


24 November 2010 at 10:43am (Last edited: 24 November 2010 10:44am), Community Member, 24 Posts

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.