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.
You can access children through the entry's descendants
property.
{# display event-information #}
<ul>
<li><a href="{{ entry.url }}">{{ entry.title }}</a>
{# display subsections #}
<ul>
{% for subsection in entry.descendants %}
<li><a href="{{ subsection.url }}">{{ subsection.title }}</a></li>
{% endfor %}
</ul>
</li>
</ul>
You can also use the nav
tag, as described in the documentation.
<ul id="nav">
{% nav entry in entries %}
<li>
<a href="{{ entry.url }}">{{ entry.title }}</a>
{% ifchildren %}
<ul>
{% children %}
</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
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
.
<li>
element isn't closed, but rather a second <li>
.
Commented
Apr 17, 2017 at 21:20
Try using .level(1)
{% for eventsEntry in craft.entries.section('events').level(1) %}
<div>
{% set image = eventsEntry.pic.first() %}
{% if image %}
<img src="{{ image.getUrl('thumb') }}" alt="{{image.title}}"/>
{% endif %}
<h4 class="center">{{ eventsEntry.title }}</h4>
{{ eventsEntry.shortDescription }}
</div>
{% endfor %}