How do you page through entries in a structure? I have a structure like below and need previous / next links on an entry such that they go back and forth between E, F, G and H. They shouldn't step into D or I.

I've been trying this, but I can't get it not to step into D or I.

{%  set prev = entry.getPrev({section: 'mySection'}) %}

    {% if not prev %}
        {% set prev = craft.entries.section('mySection').last() %}
    {% endif %}

    {{ prev.title }}

    {% set next = entry.getNext({section: 'mySection'}) %}

    {% if not next %}
        {{ craft.entries.section('mySection').order('lft desc').first().title }}
    {% endif %}

    {{ next.title }}



A

B
C
D

E
F
G
H


I

J
K
L

M
N
O
P
Craft provides many helpful methods to traverse structure sections and your use case is no exception.

Instead of using .getPrev() or .getNext(), try .getPrevSibling() or .getNextSibling() (or their aliases .prevSibling and .nextSibling.)

You could create prev/next links with something like this:

{% set prev = entry.prevSibling %}
{% if prev %}
    &lt;a href="{{ prev.url }}"&gt;{{ prev.title }}&lt;/a&gt;
{% endif %}

{% set next = entry.nextSibling %}
{% if next %}
    &lt;a href="{{ next.url }}"&gt;{{ next.title }}&lt;/a&gt;
{% endif %}