Move page of collection to last position


How can I find a specific page in a collection and move it to the last position of the collection.

I know the name of this page, so I assume I can find it by UID unless I am mixing UID and URI (always happens to me)

Also how to do this for the first page of the collection.

Thank you

$projects = page('projects')->children();
$item = $projects->findby('uid', 'project-c'); // first item: $projects->first()
$result = $projects = page('projects')->children()->not($item)->append($item->uri(), $item);

The same applies if you want to get the first. item. Instead of searching by uid, use first() to fetch the item.

Similar thread, but with structure field items: Shift first Structure item to end

1 Like