1

I'm new to Craft and exploring whether it's worth my team moving our existing, deeply-structured content site onto Craft CMS.

We have a heavily nested sitemap at the moment with 6 top-level categories and up to 5 nested levels of subcategory, eg:

- Cat 1
    - Sub Cat 1A 
    - Sub Cat 1B 
        - Sub Sub Cat 1Ba 
        - Sub Sub Cat 1Bb 
    - Sub Cat 1C 
- Cat 2
    - Sub Cat 2A 
    - Sub Cat 2B 
- Cat 3
    - Sub Cat 3A 
        - Sub Sub Cat 3Aa 
    - Sub Cat 3B

I'd like these categories reflected in URL slugs for entries, eg. /cat-1/sub-cat-1-a/ and /cat-3/sub-cat-3-a/sub-sub-cat-3-a-a etc.

I made a Category Group called "Navigation" then made a bunch of categories and nested sub-categories. I added a section and made sure it had a Category field in its Entry Types.

What I can't do, though, is get those URLs to work. I've tried following the instructions from Brandon Kelly here but I only ever get URLs generated with the top-level category slug (eg. /cat-3/{entry.slug}.

Oddly, when I select a category for an entry, no matter how many levels deep I select from, the category shown when I edit the post is always the top-level one, not the one I actually selected. Could this have something to do with it? I've ticked the "Categories in this group have their own URLs" option when editing my navigation Category Group.

1 Answer 1

1

The reason why you only see the top level category in your category field and why your URL's only use the top level category is probably because you set the "limit (number of selectable categories)" to 1 in your category field settings. That way you can only choose one category but it also only selects the top category.

Pretty irritating, I know. I had some issues with it too.

So clear that limit and it should work. I don't have a solution to limit the amount of categories selected without that option being checked. I guess you can adopt your templates for multiple categories or write a plugin to do some extra checking when selecting categories.

2
  • FWIW, we added a "Branch Limit" concept in Craft 3 that addresses that issue: github.com/craftcms/cms/issues/1388
    – Brad Bell
    Jun 12, 2017 at 23:52
  • Fantastic, this was the problem. I agree, that UI item isn't clear. I just wanted to prevent my users adding multiple categories as this might confuse the URL space, but at least now I can create my desired permalinks etc. Thank you! Jun 13, 2017 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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