<p>You're being a little too specific in your entries call. Chances are you don't have any entries at level 3. And, what happens if you have entries in a channel that might be related to those categories?</p>

<pre><code>  {% for cat in craft.categories.group('group1') %}
  &lt;p&gt;{{ cat.title }}&lt;/p&gt;
  {# You can just query all the entries in the system. Or you can provide other criteria. #}
  {% set relatedEntries = craft.entries.relatedTo(cat) %}
  {# Why the variable above? Well we can check the length and see if we have responses and avoid injecting empty HTML tags into our code #}
  {% if relatedEntries|length %}
    &lt;ul&gt;
    {% for entry in relatedEntries %}
      &lt;li&gt;{{ entry.title}}&lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
  {% endif %}
{% endfor %}
</code></pre>

<p>You can provide additional criteria to the query for entries too. The above searches the whole system for any related entries.
This would just query any items in the 'structure' section for related entries to the category.</p>

<pre><code>{% set relatedEntries = craft.entries.section('structure').relatedTo(cat) %}
</code></pre>

CC BY-SA 3.0
2017-05-18T10:54:48.980Z
I was a bit to speciffic. in my case this solved it. {% set relatedEntries = entry.children.relatedTo(cat) %}
laden
CC BY-SA 3.0
2017-05-12T17:13:46.873Z
2017-05-12T17:13:46.873Z
Ian
<p>Your code is only listing entries in the structure that are nested inside 2 parent entries. Try this:</p>

<p><code>{% for entry in craft.entries.section('structure').relatedTo(cat) %}</code></p>

<p>Also, your <code>&lt;ul&gt;</code> is inside your for loop, it should be:</p>

<pre><code>&lt;ul&gt;
    {% for entry in craft.entries.section('structure').relatedTo(cat) %}`
    &lt;li&gt;{{ entry.title }}&lt;/li&gt;
    {% endfor%}
&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2017-05-12T14:15:22.223Z
2017-05-12T14:15:22.223Z
darylknight
<p>I am trying to figure out how I can put categories to use, and I need some help.</p>

<p>I have created a category group called "group1", and 2 catogories inside called "cat1" and "cat2". and I have added the catogorie field to some articles in a structure so that I have a few linked to both cat1 and cat2.</p>

<p>My goal simply to make a forloop listing the catogorie title of both cat1 and cat2, and create an UL with the entry.title of the entries in each catogorie.</p>

<p>This is my code:</p>

<pre><code>{% for cat in craft.categories.group('group1') %}
    &lt;p&gt;{{ cat.title }}&lt;/p&gt;
    {% for entry in craft.entries.section('structure').level(3).relatedTo(cat) %}
        &lt;ul&gt;
            &lt;li&gt;{{ entry.title }}&lt;/li&gt;
        &lt;/ul&gt;
    {% endfor %}
{% endfor %}
</code></pre>

<p>This gives me the two catogorie titles, but no entry titles. I dont think I understand how to use the related to group part. Would really appreaciate some help figuring this one out.</p>

<entries><categories><relatedto>
Need a little help with basic understanding of how categories work
# Need a little help with basic understanding of how categories work

(Asked by: username_0 on 2017-05-12)

I am trying to figure out how I can put categories to use, and I need some help.
I have created a category group called "group1", and 2 catogories inside called "cat1" and "cat2". and I have added the catogorie field to some articles in a structure so that I have a few linked to both cat1 and cat2.
My goal simply to make a forloop listing the catogorie title of both cat1 and cat2, and create an UL with the entry.title of the entries in each catogorie.
This is my code:
{% for cat in craft.categories.group('group1') %}
    {{ cat.title }}
    {% for entry in craft.entries.section('structure').level(3).relatedTo(cat) %}
        
            {{ entry.title }}
        
    {% endfor %}
{% endfor %}

This gives me the two catogorie titles, but no entry titles. I dont think I understand how to use the related to group part. Would really appreaciate some help figuring this one out.

**Tags:** entries, categories, relatedto


---

## 2 answers

### Answer by username_1 on 2017-05-12. Score: 3 | Accepted answer

You're being a little too specific in your entries call. Chances are you don't have any entries at level 3. And, what happens if you have entries in a channel that might be related to those categories?
  {% for cat in craft.categories.group('group1') %}
  {{ cat.title }}
  {# You can just query all the entries in the system. Or you can provide other criteria. #}
  {% set relatedEntries = craft.entries.relatedTo(cat) %}
  {# Why the variable above? Well we can check the length and see if we have responses and avoid injecting empty HTML tags into our code #}
  {% if relatedEntries|length %}
    
    {% for entry in relatedEntries %}
      {{ entry.title}}
    {% endfor %}
    
  {% endif %}
{% endfor %}

You can provide additional criteria to the query for entries too. The above searches the whole system for any related entries.
This would just query any items in the 'structure' section for related entries to the category.
{% set relatedEntries = craft.entries.section('structure').relatedTo(cat) %}

> **Comments:**
> **username_0**: I was a bit to speciffic. in my case this solved it. {% set relatedEntries = entry.children.relatedTo(cat) %}  

---

### Answer by username_2 on 2017-05-12. Score: 3

Your code is only listing entries in the structure that are nested inside 2 parent entries. Try this:
{% for entry in craft.entries.section('structure').relatedTo(cat) %}
Also, your  is inside your for loop, it should be:

    {% for entry in craft.entries.section('structure').relatedTo(cat) %}`
    {{ entry.title }}
    {% endfor%}


---

