4

We are currently updating a brochure website, separating a single list of products into a series of sub-categories. Currently, we have a "single" section to display all products, and then a "channel" which has two entry types (products & accessories). I am trying to work out how best to create the new site structure.

I would like to display a parent page which lists all products, but then 6 sub-pages which show only the products in that category. I use the word category without specifically meaning the Craft CMS category.

I have read other posts such as Structure(s) vs. Categories for product catalog and Difference between categories and structures but these don't seem to help. There seems to be a bit of confusion surrounding Craft categories, structures and using singles to divide the content.

How could we re-organise the existing content into this new structure?

5

Typically, I will create a single for each product "home" page, and then a channel for my products or sub-pages. I will generally use a channel vs. a structure unless I know I want to manually control the order or nest entries.

Let's say I have a website about automobiles. I would create a section (single) called cars. That section would have the url of site.com/cars and the template would be located at /templates/cars/index.html. This is the template that would be responsible for pulling in all of the cars I have.

This is where things can get tricky, or not...all depends on how you want to roll.

If you created a channel called automobiles (or whatever you like), you could enter each car you have as an entry within the channel. Then on your cars single, you can tell Craft to loop through all entries in the automobiles channel.

Since you can't nest a channel entry, I would use categories to "tag" your cars. For example, I would create a category called Sports Cars and relate any sports cars I have to that category. You could also create a category for Trucks or Vans to help group/classify each car you had.

This would also allow you to create sudo-landing pages for each type of car. For example, site.com/cars/sports-cars would get all entries that are tagged as a sports car. You could do this for trucks, or you could even divide categories up into trucks/4-wheel-drive so not only would a truck show when I requested trucks, it would also show in my 4-wheel-drive options.

From an authoring experience, this is great. I don't care specifically where I have to create the entry - all I know is that I have a car, and it goes in the cars "bucket" (automobiles channel). It's within that entry (the car entry itself) you are choosing where it is available to the end user.

You could even create different entry types for the kind of automobile you are creating. This would allow you to have a cleaner screen as some fields don't apply for all automobiles.

To illustrate a structure, think about the staff who is in charge of this car-selling company.

I would create a structure called staff. It would have the url of site.com/about/staff and a template of /templates/about/staff/_entry

From there you could create an entry for each person. You can then create "parent" entries for the hierarchy of the office.

For example:

- Management
    |-- Bob McKenzie
    |-- Doug McKenzie
- Sales Team
    |-- Tyler Durden
    |-- Agent Smith

By using a structure here, you can not only manually set the order of which group (management or sales) is first, but you can also arrange the order of the team members within.

So to answer your question directly:

I would like to display a parent page which lists all products, but then 6 sub-pages which show only the products in that category. I use the word category without specifically meaning the Craft CMS category

I would do this:

Create a single and give it a name of the url that you would like to show all products on. To use my example, this would be cars.

Create a Category to relate your products to Ex: Sports Cars.

Then create a channel - called Products. Every product will go here. When you are creating these product entries, use a Channel Field type so you can select which category the given product belongs to (Sports Cars).

Then on your cars page, you would tell Craft "Hey, get every single product". If I navigate to site.com/cars/sports-cars you can tell Craft "Hey, only get me cars that are related to sports cars".

Kind of a long-winded answer, hope it helps get you going.

  • Great answer - thank you. I managed to get something working before I read your answer by using different entryTypes on my channel. I then use routes to point back to my template which checks the URL path (the entry type handle) and loads the sub-set of products. Your solution seems to be a bit more flexible so I will have a go at that next. Thanks again – Alex Holsgrove May 6 '16 at 13:41
  • You are very welcome! Personally, I think the difficulty lies in the fact that there are so many ways you can do things. You never really know you're headed down the right path until you try it and run into something that causes you to try another direction. – Damon May 6 '16 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.