<p>Sometimes you need the same parent/siblings menu from various POVs (parent or children). Here's what I came up with:</p>

<pre><code>{# Parent / Children subnavigation, either from the perspective of the parent or a child #}

{% if entry.level == 1 %}
  {% set parent = entry %}
  {% set children = entry.getDescendants().all() %}
{% elseif entry.level == 2 %}
  {% set parent = entry.getAncestors().one() %}
  {% set children = entry.getSiblings().all() %}
{% endif %}

&lt;h1&gt;&lt;a href="{{parent.url}}"&gt;{{parent.title}}&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
    {% for child in children %}
    &lt;li&gt;&lt;a href="{{child.url}}"&gt;{{child.title}}&lt;/a&gt;&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<p>I wonder if that's a detour and there's an easier way?</p>

CC BY-SA 4.0
2018-09-03T09:30:58.450Z
2018-09-03T09:30:58.450Z
Urs
<p>For this you should be able to use the getSibling() method which:</p>

<p>"Returns an ElementCriteriaModel object prepped to return the entry’s siblings (if it lives in a Structure section)."</p>

<p><a href="https://docs.craftcms.com/v2/templating/entrymodel.html#getsiblings" rel="nofollow noreferrer">https://docs.craftcms.com/v2/templating/entrymodel.html#getsiblings</a></p>

<pre><code>{% set siblings = entry.getSiblings().all() %}

&lt;ul&gt;
    {% for page in siblings %}
        &lt;li class="item-contentmenu"&gt;
            &lt;a href="{{ page.url }}"&gt;{{ page.title }}&lt;/a&gt;
        &lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 3.0
2015-07-30T11:13:35.333Z
I've tried this instead of the code below but with no success again the model returns Null for siblings. Any ideas why?
Lettie
CC BY-SA 3.0
2015-07-30T16:51:10.500Z
could you show how you tried to implement the getSibling()? But to note it wont really improve on the answer you've given.
George D
CC BY-SA 4.0
2015-07-30T10:19:14.630Z
2018-09-06T18:38:49.947Z
2018-09-06T18:38:49.947Z
George D
<p>Ok I've worked this out from above and adding some other code and now it works as below:</p>

<pre><code>{% set parent = entry.getAncestors().first() %}
{% for subnav in craft.entries.section('mySection').descendantOf(parent).descendantDist('1') %}
    &lt;li&gt;&lt;a href="{{ subnav.url }}"&gt;{{ subnav.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<p>Hope this assists someone else.</p>

CC BY-SA 3.0
2015-07-30T11:23:42.730Z
2015-07-30T11:23:42.730Z
Lettie
<p>I have a structure as follows:</p>

<ul>
<li>Parent 1

<ul>
<li>Child 1</li>
<li>Child 2</li>
<li>Child 3</li>
</ul></li>
<li>Parent 2

<ul>
<li>Child 1</li>
<li>Child 2</li>
<li>Child 3</li>
</ul></li>
<li>Parent 3

<ul>
<li>Child 1</li>
<li>Child 2</li>
<li>Child 3
etc...</li>
</ul></li>
</ul>

<p>On my Child entry pages I want to pull out the other child entries under that parent to use as navigation. I think this should be fairly straight forward but I can not find any documentation on it. So far I have the below but this pulls out all level 2 child entries and not just the entries for the specified parent.</p>

<p>Any help much appreciated.</p>

<pre><code>{% for subnav in craft.entries.section('mySection').level(2).find() %}
    &lt;li&gt;&lt;a href="{{ subnav.url }}"&gt;{{ subnav.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<structure><navigation>
How do you pull out second level structure entries based on their parent?
# How do you pull out second level structure entries based on their parent?

(Asked by: username_0 on 2015-07-30)

I have a structure as follows:

Parent 1


Child 1
Child 2
Child 3

Parent 2


Child 1
Child 2
Child 3

Parent 3


Child 1
Child 2
Child 3
etc...


On my Child entry pages I want to pull out the other child entries under that parent to use as navigation. I think this should be fairly straight forward but I can not find any documentation on it. So far I have the below but this pulls out all level 2 child entries and not just the entries for the specified parent.
Any help much appreciated.
{% for subnav in craft.entries.section('mySection').level(2).find() %}
    {{ subnav.title }}
{% endfor %}

**Tags:** structure, navigation

---

## 3 answers

### Answer by username_0 on 2015-07-30. Score: 5 | Accepted answer

Ok I've worked this out from above and adding some other code and now it works as below:
{% set parent = entry.getAncestors().first() %}
{% for subnav in craft.entries.section('mySection').descendantOf(parent).descendantDist('1') %}
    {{ subnav.title }}
{% endfor %}

Hope this assists someone else.


---

### Answer by username_1 on 2018-09-03. Score: 2

Sometimes you need the same parent/siblings menu from various POVs (parent or children). Here's what I came up with:
{# Parent / Children subnavigation, either from the perspective of the parent or a child #}

{% if entry.level == 1 %}
  {% set parent = entry %}
  {% set children = entry.getDescendants().all() %}
{% elseif entry.level == 2 %}
  {% set parent = entry.getAncestors().one() %}
  {% set children = entry.getSiblings().all() %}
{% endif %}

{{parent.title}}

    {% for child in children %}
    {{child.title}}
    {% endfor %}


I wonder if that's a detour and there's an easier way?


---

### Answer by username_2 on 2015-07-30. Score: 1

For this you should be able to use the getSibling() method which:
"Returns an ElementCriteriaModel object prepped to return the entry’s siblings (if it lives in a Structure section)."
https://docs.craftcms.com/v2/templating/entrymodel.html#getsiblings
{% set siblings = entry.getSiblings().all() %}


    {% for page in siblings %}
        
            {{ page.title }}
        
    {% endfor %}

> **Comments:**
> **username_0**: I've tried this instead of the code below but with no success again the model returns Null for siblings. Any ideas why?  
> **username_2**: could you show how you tried to implement the getSibling()? But to note it wont really improve on the answer you've given.  

---

