2

I'm just getting to grips with Craft but it seems very flexible. To try it out I have set up a structure to store some sample products. These products have an image, text, tags and belong to a category (E.g cakes). I can sort and output products, display in groups even sort by tag - brilliant.

One thing I struggling with is how assign a image and other fields to the category? So that I can then have a page with a list of categories each with an image and text Or even output a single category that I want to highlight on another page?

Should this be a "parent" entry? If so how do I assign a set of fields to the parent item but not the child?

Possibly I am thinking about approaching this the wrong way and I should create a "types" structure in which the entries have a required field that is the "category" and use this to search for any products of matching category?

Confused - any pointers appreciated.

1 Answer 1

3

The Craft Categories page is very useful.

To assign an entry to a category, create a category field, and require it in the entry type (you are probably already doing this).

When you create a Category Group you can edit the field layout, and add an image field and a text field for the category. Then to edit that content, double click on the category itself (from the right-side category menu), and you will get a modal dialog where you can edit the text and image.

To list the categories in myCategoryGroup you do:

{% set categories = craft.category.group('myCategoryGroup') %}
{% for cat in categories %}
  {{cat.title}} - {{cat.image}} {# assuming image is the name of the image field #
{% endfor %}

Craft site has an article on How do I list the entries related to a category?.

1
  • Thank you! My first issue was not realising there was a "Field Layout" tab on the category group edit page. On top of that I'm not sure I would have noticed you could "double click on the category itself".
    – jamus
    Commented Jul 31, 2014 at 8:57

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.