13

The recent updates to categories have been great and provide a lot of flexibility. But now I find myself struggling to decide what should be a category group and what should be a structure.

For example we are working on a site where a lot of the content will be segmented by city. Originally I had just assumed that cities would be a entry section but now feeling like categories make more sense semantically?

So my question is what are the functional differences between categories and structures? As far as I can tell they are:

  1. The category fieldtype does not let you reorder the selected categories, the way you can with related entries field. They always stay in the category groups order
  2. Categories don't have a post date or expiration date
  3. Categories don't have authors
  4. Categories don't have versioning

Are there any other important differences I should consider? It seems like the only advantages are that they get their own tab, and that the ordering is consistant across all related entries

3

Great question. Categories are used to organize a variety of content including entries, assets, even other categories. Categories themselves do not have content (besides maybe a description and key image), but can be related to content. They are a great way to group related entries together and provide a semantic structure (little s) to your content.

Structures (big S) are entries. They are content. The biggest difference between Structure entries and Channel entries is that Structure entries can have children, parent, and sibling entries. Additionally, Structure entries should not be "date driven" like Channel entries would be (blogs, for example, are date driven).

If your content needs to be segmented by cities, and is in some way date sensitive, I would recommend setting up city Categories and have a Channel for your entries. Fortunately, Categories can also have parent, children, and siblings, so if you needed to organize your cities by state, you could accomplish that easily with Categories. This is why the category fieldtype does not let you reorder them.

For quick reference, check out the documentation on section types and categories.

  • Thanks Aaron. All that makes sense. It seems like all of your comments are more semantic then technical. Technically categories can have as much or more content then entries. Im curious in this post to really learn what if any technical differences there are between categories and entries. – Keith Mancuso Apr 1 '15 at 20:25
  • 1
    I think the semantics of it are a very important differentiator. Craft offers a lot of technical flexibility. But the real reason to choose a category or a structure may come down to what is simpler for the end users/client to understand. Say you have a list of employees and they belong to departments. Both employees and departments technically could be categories or both could be structures, but the most obvious choice would be to make employees a structure and departments a category group. It just makes more sense. – Alex Roper Apr 20 '15 at 8:19
  • But categories can have as much content as anything else; you can add fields and field groups to them. I'm struggling to see how Categories are in any practical way different from a Structure - which gives you more options. – Matt Wilcox Apr 8 '16 at 15:28
2

You touch on many of the important differences already, but one of the key factors that influences whether I choose a category or structure is whether I need to manually order the members of the group.

For example, when listing all entries in a certain category, you can choose to order them by various criteria using the order parameter on craft.entries. From the docs:

Possible values include 'title', 'id', 'authorId', 'sectionId', 'slug', 'uri', 'postDate', 'expiryDate', 'dateCreated', and 'dateUpdated', as well as any textual custom field handles.

But I don't think you can drag and drop them into the order you want in the same way you can with entries in a structure. When listing all the entries in a structure, you can choose an arbitrary order in which to list them.

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.