3

I have a section of book entries with a categories field called "Genre". A book can fall into multiple genres. A stripped down version of the categories works something like this:

  • Fiction
    • Crime, Thrillers & Mystery
      • Mystery
      • Thrillers
      • Action & Adventure
    • Fantasy
  • Non-Fiction
    • etc

On the home page, there is to be a feature panel linking to a particular genre, let's say Thrillers for example.

For the feature panel field, I need to limit this to a single genre, but if I set the limit on the categories field to 1 and select Thrillers, it just selects Fiction.

Of course I could just remove the limit and then use twig to get only entries from the deepest selected category, but I don't want to open up the possibility that they'll select multiple categories.

Is there any way around this? I can't help but feel like the limit option on the categories fieldtype is a bit broken.

* Update for clarity *

Categories group called Genre is structured as above
Books channel has a category field called Genre, allowed to select multiple genres
Homepage has a category field called Related Genre

The intention is to choose a single category for Related Genre to output the books which have that category selected in Genre.

This is all entirely within the admin area, so code is effectively irrelevant at this point.

Perhaps some images will make this clearer:

In the entry, I attempt to select Thrillers:
Attempt to select Thrillers

But after clicking select, it has just selected Fiction:
Selected fiction instead

3
  • I don't entirely understand your question. You are providing a checkbox to allow them to select a single category on the front-end? Please elaborate a bit more and include your code as well. Commented Mar 7, 2016 at 19:11
  • Hi Christopher, thanks for replying. There is no code to speak of as this is an issue within the admin itself - please see updated answer for some more details.The docs state that the limit includes parent categories, so I'm not sure if anything can be done, but this seems like a logical approach to me, so seems odd that I can't do it.
    – Jammooka
    Commented Mar 7, 2016 at 20:33
  • This is a issue that I'm looking to answer as well. When selecting a child category, the parent category appears as the selected item in the entry. craftcms.stackexchange.com/questions/14043/… Commented Mar 8, 2016 at 2:34

1 Answer 1

1

You could use a structure for Genre rather than categories. This would let you select Thrillers as a single entry.

1
  • As it happens, I've changed my thinking on this, so I'm allowing unlimited categories to be selected, but using an 'and' relation. For example, they could select humour and crime and advertise it as "Crime Capers". That said, I think to do what I originally asked, a structure may well be the only way, so I'll accept this as the answer - thanks!
    – Jammooka
    Commented Mar 8, 2016 at 21:43

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.