Hello!
I want to keep sort some pages in my page tree within a single parent, but then have the URLs for those pages ignore their topmost parent.
So for example, if the page is at: [home]/buildings/architect-name/building-name
I want the URL to be /architect-name/building-name
I've search around the forum, and the solution that comes up everywhere is a version of the code from this post:
/**
* This hook modifies the default behavior of the Page::path function (and thereby Page::url)
*
* The primary purpose is to redefine blog posts to be accessed at a URL off the root level
* rather than under /posts/ (where they actually live).
*
*/
wire()->addHookBefore('Page::path', function($event) {
$page = $event->object;
if($page->template == 'post') {
// ensure that pages with template 'post' live off the root rather than '/posts/'
$event->replace = true;
$event->return = "/$page->name/";
}
});
And I can use a version of that to successfully get buildings/architect-name to appear as /architect-name
But /buildings/architect-name/building-name still appears as /buildings/architect-name/building-name
Is there a way to get URLs to ignore/remove that topmost parent even when the page has a grandchild?
Any help much appreciated!