joe_g Posted March 22, 2017 Share Posted March 22, 2017 Hi, is there a way to move the position of a page to first with the API? I ran into an old problem: I'd like new pages to appear first, instead of last, but still retain manual drag-drop order – discussed in 2013: I figure I could do a save hook that moves the page to the top, if there is a way via the API.. Link to comment Share on other sites More sharing options...
kixe Posted March 22, 2017 Share Posted March 22, 2017 If it is not necessary to sort the pages additionally manually the last one can also be the first one if you reverse the order. Just go to the parent template settings select created in Sort settings for children and check Reverse sort direction Link to comment Share on other sites More sharing options...
horst Posted March 22, 2017 Share Posted March 22, 2017 3 Link to comment Share on other sites More sharing options...
kixe Posted March 22, 2017 Share Posted March 22, 2017 @horst Thanks. Didn't know about that. Will have a look inside asap. 1 Link to comment Share on other sites More sharing options...
joe_g Posted March 24, 2017 Author Share Posted March 24, 2017 amazing, thank you! Horst, that looks perfect - will try that one Link to comment Share on other sites More sharing options...
kixe Posted March 26, 2017 Share Posted March 26, 2017 How to set page->sort via API The variable $page is the page you want to move // move to beginning $pages->sort($page, 0); // move to end $lastSibling = $page->siblings('include=all')->last(); $pages->insertAfter($page, $lastSibling); // move 1 step forward $pages->insertAfter($page, $page->next); // move 1 step backwards $pages->insertBefore($page, $page->prev); // move to any index position $newIndex = 0; if ($newIndex === 0) $pages->sort($page, 0); else { $futureBefore = $page->siblings('include=all')->eq($newIndex); $futureBefore = $futureBefore? $futureBefore : $page->siblings('include=all')->last(); $pages->insertAfter($page, $futureBefore); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now