Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Pages order in menu/cms

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

Page: 1 2
Go to End
Author Topic: 4888 Views
  • Jarek
    Avatar
    Community Member
    30 Posts

    Pages order in menu/cms Link to this post

    Hello

    When I'm creating subpage in CMS, page is added as last tree leaf (in menu also is last). I want to put newest pages at first positions, not last. So each time I'm adding page I have to move it to the first position (very irritating when there is menu subpages). Is there easy way to modify cms code to add pages default at first place?

  • Brig
    Avatar
    Community Member
    26 Posts

    Re: Pages order in menu/cms Link to this post

    I'm interested in doing this as well. Especially for a news section. The latest article should appear at the top.

    Anyone knows how this can be done please?

  • cbartgu
    Avatar
    Community Member
    12 Posts

    Re: Pages order in menu/cms Link to this post

    Anyone have any ideas on how to do this?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Pages order in menu/cms Link to this post

    Can't say if this will work for new pages but you can specify a default_sort on Page.php which will display the pages sorted in a given order

    Add this to your page.php, reload the admin with a ?flush=1 and see what happens

    static $default_sort = "Created DESC";

    Tho I think adding will append it always to the bottom, but try that and see what happens

  • cbartgu
    Avatar
    Community Member
    12 Posts

    Re: Pages order in menu/cms Link to this post

    Thanks for the reply, I want to display the pages by the date order they are in (my date field), not the creation date, though, also where abouts do you put the code,

    if you could help with that, that would be great,

    Thanks,

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Pages order in menu/cms Link to this post

    @ cbartgu - Put that in your PageType class, so if you wanted to add it to ArticlePage you would ahve the following:

    class ArticlePage extends Page{

    static $db = array(
    'Date' => 'Date'
    );

    static $default_sort = "Date DESC";

    function getCMSFields(){

    etc.....

    }

    }

  • cbartgu
    Avatar
    Community Member
    12 Posts

    Re: Pages order in menu/cms Link to this post

    Thanks again, I tried it but it does not change the child pages are still ordered by the id I think, this is what I have got,

    class BreakPage extends Page {
    static $db = array(
    'Date' => 'Date',
    'Category' => "Enum('cat1,cat2,cat3')",
    'Price' => 'Text',
    'KidsPrice' => 'Text',
    'Hilight' => 'Boolean',
        'Duration' => "MultiEnum('1 night only,2 nights,3 nights,4 nights,5 nights,Week Long')",
        'Type' => "MultiEnum('Theme,Family,Adult')"
    );

    // an Article can have many Category objects associated with it.
    // calling $this->getManyManyComponents('Categories') retrieves the associated Category objects.

    // this classes default parent is an ArticleHolder page type
    static $default_parent = 'ActivityHolder';

    static $default_sort = "Date DESC";

    function getCMSFields() {
    $fields = parent::getCMSFields();

    etc

  • Thomashv
    Avatar
    Community Member
    33 Posts

    Re: Pages order in menu/cms Link to this post

    I also have a problem width this:
    static $default_sort = "Created DESC";
    or
    static $default_sort = "Created ASC";
    doesn't change anything. Running SilverStripe 2.4.

    Does anyone have a clue why this happens? Could it be a default sort overriding the sort added to the class somewhere?

    4888 Views
Page: 1 2
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.