1

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.

i.e

/vacation/snow
/vacation/coastal

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

/advice/what-to-bring
/advice/weather-warnings
/contact

So basically I want to do this...

if segment1 = entry url segment1 display entries.

ljm
  • 141
  • 1
  • 8

1 Answers1

3

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 %}
<ul>
    {% for entry in entries %}
        <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}
</ul>

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 %}
<ul>
    {% for entry in entries %}
        <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}
</ul>

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

{% set entries = entry.siblings %}
Douglas McDonald
  • 13,457
  • 24
  • 57