Should be easy i thought. How can i display all entries from a section from a certain category?
This is my code now, but nothing shows up (screenshot bottomleft):
{% set category = craft.categories.slug('b2c').first() %}
{% set entries = craft.entries.section('homeBlocks').relatedTo(category).find() %}
{% for entry in entries %}
{{ entry.title }}
{% for cat in entry.businessSegment %}
{{ cat }}
{% endfor %}
{% endfor %}
This code shows all entries (screenshot topleft), and you can see there are entries with b2c:
{% set category = craft.categories.slug('b2c').first() %}
{% set entries = craft.entries.section('homeBlocks').find() %}
{% for entry in entries %}
{{ entry.title }}
{% for cat in entry.businessSegment %}
{{ cat }}
{% endfor %}
{% endfor %}
My Category Group is called Business Category (with handle "businessCategory"). It contains two categories:
- b2c (slug "b2c")
- b2b (slug "b2b")
The field handle used in the section "homeBlocks" is "businessSegment"
Where's the error? :)
find()
off of yourrelatedTo
? So it becomes:{% set entries = craft.entries.section('homeBlocks').relatedTo(category) %}