1

I know this is a really suck egg question, but I finding the Craft docs far less straightforward than EE (I'm just switching over), and so I'm struggling with the easy task of displaying an entry's category.

{% for entry in craft.entries.section('blog').limit(1) %}
   <h2>{{ entry.title }}</h2>
                              
   
   {% if entry.byLine %}
   <h3>{{ entry.byLine }}</h3>
   {% endif %}
                           
   <h3>Category: { ???? } </h3>
   
   {% endfor %} 

Can anyone help?

1

To display a single category you'll need to do something like this:

{% set category = entry.categoryfieldhandle.one() %}
{{category.title}}

To display multiple categories:

{% set categories = entry.categoryfieldhandle.all() %}
{% for category in categories %}
{{category.title}}
{% endfor %}

Replace categoryfieldhandle with the handle you used for your field.

You can find more in depth and alternative ways in the docs:

https://craftcms.com/docs/3.x/relations.html

Since you're new to craft I recommend taking a look at the following course https://craftquest.io/courses/craft-cms-3-tutorials to help get you started.

0

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.