Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$default_sort on pages beneath SiteTree class has no effects at all #848

Closed
sommereder opened this issue Sep 16, 2013 · 5 comments
Closed

Comments

@sommereder
Copy link

I can change the value inside SiteTree model, but when I try to give subpages a default sort, the variable $default_sort has no effect.

@simonwelsh
Copy link
Contributor

It does, you just need to be getting instances of that class rather than SiteTree (so MyPage::get()).

@sommereder
Copy link
Author

So it shall not effect the page's order in the CMS SiteTree?

As example: I would like to sort pages by Date for a Blog. The pages should be displayed by test in the CMS SiteTree so that the newest is shown first.

@simonwelsh
Copy link
Contributor

You can override stageChildren($showAll = false) (the default implementation's in Hierarchy) on your holder page type to achieve this.

@sommereder
Copy link
Author

Sounds good.

How to achieve to put the latest created page on top without loosing the ability to sort manually by drag and drop?

Right now I have this code inside onBeforeWrite() but it's not executed each time I create a page, what's really wired...

if(!$this->FirstSort) {
$_parentID = ($this->ParentID) ? $this->ParentID : 0;
$_siblings = BlogArticlePage::get()->filter(array('ParentID' => $_parentID))->sort('Sort');
foreach($_siblings as $_sibling) {
$_sibling->Sort = intval($_sibling->Sort, 10) + 1;
}
$this->Sort = 0;
$this->FirstSort = true;
}

I think having the ability to add new pages on top or bottom of its siblings should be an easy to handle option of SilverStripe CMS core.

@sommereder
Copy link
Author

Ok, Sort starts with 1 not with 0. Got that. Now I just need to find out how to write back the new Sort value for all other objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants