Jump to:

5520 Posts in 1734 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Custom sorting for SiteTree

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

Page: 1
Go to End
Author Topic: 1745 Views
  • timon
    Community Member
    4 Posts

    Custom sorting for SiteTree Link to this post

    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.

  • JL
    Community Member
    10 Posts

    Re: Custom sorting for SiteTree Link to this post

    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

  • DNA
    Community Member
    24 Posts

    Re: Custom sorting for SiteTree Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.