Newbie here with hopefully a simple question...

I have a structure as per the image below where I want to only show the parent item and it's children on their pages.

I want to exclude the other entries but they should show on their own pages.

My structure


You can access children through the entry's descendants property.

{# display event-information #}
    <li><a href="{{ entry.url }}">{{ entry.title }}</a>
    {# display subsections #}
            {% for subsection in entry.descendants %}
                <li><a href="{{ subsection.url }}">{{ subsection.title }}</a></li>
            {% endfor %}

You can also use the nav tag, as described in the documentation.

<ul id="nav">
    {% nav entry in entries %}
            <a href="{{ entry.url }}">{{ entry.title }}</a>
            {% ifchildren %}
                    {% children %}
            {% endifchildren %}
    {% endnav %}

More generally speaking, you can use any of the following properties of the EntryModel to traverse the structure: parent, children, descendants, ancestors, siblings, nextSibling, prevSibling, and level.

  • Worth noting that the top example has a typo on line 7, the <li> element isn't closed, but rather a second <li>. – Christopher Kennedy Apr 17 '17 at 21:20
  • @ChristopherRobertKennedy Thanks! Fixed. Btw... feel free to edit when you find an obvious error like that, assuming you have permission. – Douglas McDonald Apr 19 '17 at 22:04
  • For some reason, I was having problems accessing the edit feature in Chrome. Seems to work for me in Safari now, though. ¯_(ツ)_/¯ – Christopher Kennedy Apr 20 '17 at 1:11

Try using .level(1)

{% for eventsEntry in craft.entries.section('events').level(1) %}
        {% set image = eventsEntry.pic.first() %}

        {% if image %}
            <img src="{{ image.getUrl('thumb') }}" alt="{{image.title}}"/>
        {% endif %}

        <h4 class="center">{{ eventsEntry.title }}</h4>

        {{ eventsEntry.shortDescription }}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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