<p>Something like this should do the trick! You want to get all the section parent entries, then search for child entries that are related to the category you want. </p>

<pre><code>{% set parents = craft.entries.section('your_structure_handle').level(1) %}

{% for parent in parents %}
    {% set children = craft.entries.decendantOf(parent).relatedTo(category) %}
    {% if children|length %}
        &lt;h1&gt;{{parent.title}}&lt;/h1&gt;
        &lt;ul&gt;
        {% for child in children %}
            &lt;li&gt;{{child.title}}&lt;/li&gt;
        {% endfor %}
        &lt;/ul&gt;
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-10-05T21:11:24.997Z
2015-10-06T06:56:39.127Z
2015-10-06T06:56:39.127Z
Aaron Berkowitz
<p>I'm a newbie, so please excuse this if its a super simple question. I have a structure set up like so: </p>

<pre><code>• Parent Section 1
  - Child 1A (category: pro-users)
  - Child 1B (category: pro-users)
  - Child 1c

• Parent Section 2
  - Child 2A 
  - Child 2B
</code></pre>

<p>I am wanting to output a navigation/landing page with the children viewable or not based on what category they are set to. So for example, on a specific page, I just want items with category "pro-users" (two entries specified above) to show up, with their parent title, and not any of the others. I also don't want the parent titles of sections that don't contain matching elements (Parent Section 2) to show. So, in this example where I just want the children with category "power-users" to show up, it would only show me: </p>

<pre><code>PARENT SECTION 1
   Child 1A
   Child 1B
</code></pre>

<p>And nothing else. Please ask for more specifics if this doesn't make sense. I just can't figure out how to a) only show the children that are matching the categories I specify (in this case "pro-users") and to also not show the subsequent parent title if there are no matching children (as is the case for Parent Section 2).</p>

<p>Thanks in advance for your help, I really really appreciate it!</p>

<structure><children><parents>
Showing/Hiding children of a Structure based on categories
# Showing/Hiding children of a Structure based on categories

(Asked by: username_0 on 2015-10-05)

I'm a newbie, so please excuse this if its a super simple question. I have a structure set up like so: 
• Parent Section 1
  - Child 1A (category: pro-users)
  - Child 1B (category: pro-users)
  - Child 1c

• Parent Section 2
  - Child 2A 
  - Child 2B

I am wanting to output a navigation/landing page with the children viewable or not based on what category they are set to. So for example, on a specific page, I just want items with category "pro-users" (two entries specified above) to show up, with their parent title, and not any of the others. I also don't want the parent titles of sections that don't contain matching elements (Parent Section 2) to show. So, in this example where I just want the children with category "power-users" to show up, it would only show me: 
PARENT SECTION 1
   Child 1A
   Child 1B

And nothing else. Please ask for more specifics if this doesn't make sense. I just can't figure out how to a) only show the children that are matching the categories I specify (in this case "pro-users") and to also not show the subsequent parent title if there are no matching children (as is the case for Parent Section 2).
Thanks in advance for your help, I really really appreciate it!

**Tags:** structure, children, parents


---

## 1 answers

### Answer by username_1 on 2015-10-05. Score: 2 | Accepted answer

Something like this should do the trick! You want to get all the section parent entries, then search for child entries that are related to the category you want. 
{% set parents = craft.entries.section('your_structure_handle').level(1) %}

{% for parent in parents %}
    {% set children = craft.entries.decendantOf(parent).relatedTo(category) %}
    {% if children|length %}
        {{parent.title}}
        
        {% for child in children %}
            {{child.title}}
        {% endfor %}
        
    {% endif %}
{% endfor %}


---

