I have a Structure that has the URL setup like this..

Top-Level Entries - {slug}
Nested Entries - {parent.uri}/{slug}

How do I list all entries that have the same segment1 of their URL as to what is on the current page the user is on.

i.e if I am on page http://example.com/vacation

I want to list all structure entries that have 'vacation' as the first segment of the URL.



but it would not show any entries from the structure that are like this:


So basically I want to do this...

if segment1 = entry url segment1 display entries.

1 Answer 1


Since you already have an entry in the same structure, the simplest method is probably to use the parent and descendants properties of the EntryModel.

{% set entries = entry.parent.descendants %}
    {% for entry in entries %}
        <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}

A more round about way would be to get the segment through craft.request.segment, use that to get the entry, and use descendants to get the children.

{% set segment = craft.request.segment(1) %}
{% set entries = craft.entries.section('myStructureHandle').slug(segment).first.descendants %}
    {% for entry in entries %}
        <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}

Or, if you only want the siblings without the current entry, you could use:

{% set entries = entry.siblings %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.