Jump to content

Same Path different Parent (sort of)


Bike
 Share

Recommended Posts

Hi everyone, I didn't know what to even search for so I started this topic.

I have a page say 'books' with some children such as 'specials', 'q&a', 'upcomig' etc. On that page I want to list books which are at the moment as well children what causes the books and the other pages mentioned above get mixed up in the same branch at the admin page and that's something I do not want.

I'd like to have a seperate hidden page 'all books' where I draw all the books from but they should behave like being children of 'books''. That's because I want to like to detail pages and their paths should be /books/book-1 etc. and not /all-books/book-1 ...

I hope it gets clear and is somehow possible. Thanks, already!

Link to comment
Share on other sites

I’m not certain I correctly understood the problem, but in general it will save you some headaches if you set up the page tree according to the canonical urls you want.

What should be the canonical urls for specific books and specific categories? If you want a The Hobbit’s $page->url to be /books/the-hobbit and the fantasy section’s to be /books/fantasy, go with the mixing!

If you want every book to have sort of a primary category, put each book under a category. Then it’ll be /books/fantasy/the-hobbit. You can still have /books/the-hobbit by using urlSegments, but you’ll obviously have to watch out for books that have the same page name as a category. And you will have to generate those links yourself somehow.

I suppose you should also ask yourself if you really need the same page to be accessible by different urls?

  • Like 1
Link to comment
Share on other sites

Thanks @Jan Romero, you understood right.

To make it more clear: In admin I want all the books in a seperate branch so my client does not get confused with the other pages. On the actual page then I want all the books to be on /books/book-1 ... along with the other pages such as books/q-and-a or /books/upcoming. I do not want one page with different URLs, I just want to separate them in the admin.

You mentioned urlSegments which I'm going to have a look at. ✌️

Link to comment
Share on other sites

In general, page urls following the page tree is The ProcessWire Way™, and it’s a pretty good idea, so I’m not exactly advising you to deviate from that, but if you want to do it, it might be worth considering the other way around:

/home/
    /books/
        /the-hobbit/
        /the-very-hungry-caterpillar/
        /the-luzhin-defence/
    /categories/
        /non-fiction/
        /graphic-novels/
        /really-graphic-novels/

To make your life easier you could even hook Page::path to change the urls of categories to what you want, but you don’t have that from me.

(Actually, fooling around with that I just discovered a bug in a urlSegment validation regex, thanks!)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...