Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 6 down vote accepted

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 %}
    <a href="{{ prev.url }}">{{ prev.title }}</a>
{% endif %}

{% set next = entry.nextSibling %}
{% if next %}
    <a href="{{ next.url }}">{{ next.title }}</a>
{% endif %}
share|improve this answer
Thanks for your help Stuart. Much appreciated! – user1070143 Jun 20 '14 at 9:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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