An item can be in different collections, for example:
collection A: item A > item B > item C
collection B: item B > item C > item A
When the user navigates on the website, he pass through a collections page, click a collection, and then click an item.
On the Item page, how to display the collection which was clicked on the previous collection page (and the related items in that specific order, in a breadcrumb style)?
Example:
the user click on collection A, then item A, he lands on the item page with a breadcrumb like: collection A: item A > item B > item C
the user click on collection B, then item A, he lands on the item page with a breadcrumb like: collection B: item B > item C > item A
So currently when you call the item page, there is nothing in the URL to indicate that the page was called from a collection page, right?
I think for your use case, a route would be the best option, so that you can then pick the virtual parent (i.e. the collection from the path in the URL), and then get the children by just looping through the structure field.
I don’t think a breadcrumb style navigation is the correct way of displaying those pages though, because the items are not children of the other items.
On a side note: With your setup, you will end up with the same content available at different URLs, which is bad for SEO. Are you taking care of this somehow?
Thank you guys,
I am trying to understand and make this work now.
About the url, I think, I would prefer an url like this: /items/:any/in-collection/:any
So that the default url would be items/item-a and I can put a link rel="canonical" on each duplicated content page. If there is no /in-collection part in the url, I would pick up a default collection.
How would be routes config in that case? Any idea or suggestion?
which works fine when a correct url is reached (like colections/collection-a/resource-a). When the url is an wrong, it makes an error instead of a page 404 (because /items/wrong-slug doesn’t exists). How to fix that?
TypeError
Argument 1 passed to Kirby::render() must be an instance of Page, boolean given, called in /kirby/kirby/component/response.php on line 27
This doesn’t make sense to me… Not everyone is going to visit your items through the collection pages. E.g. what if a user comes directly from a search engine? And as @texnixe mentioned, duplicate content is a pain for SEO.
If you really insist on doing so, have you considered cookies?
Yes I agree it looks weird if the goal was strictly to access the /item-x pages. Here is the client requirement: make a website to presents several modules belonging to different curriculums. A module can belong to many curriculums. When you navigate to the page of a module, you should be able to go to the next module depending on the curriculum you chose in the first place. Does it make more sense?
I don’t think SEO duplicate is a problem if the link rel="canonical" points to an arbitrary default version. Or is it?
the /items and /items/item-x pages won’t be visible and therefore not directly accessible from the menu, so the default referenced version should be a /collection/collection-x/item-x page.
Does it make more sense to do it with cookies? If so, how would you do that?
Well, the question is if the items need to be accessible via the items page directly or not, and if so, then why?
The setup might make sense if the purpose if the items page is to avoid having to add the same content multiple times within the collections (if we think of these collections as a sort of categories to which an item belongs and where an item can belong to several categories).
You should then block access to the direct (/items/item) URL as well (via server config, .htaccss, route or template) and only make those pages accessible via the collections.