Answers.Body: <p>Craft provides many helpful methods to traverse structure sections and your use case is no exception.</p>
  
  <p>Instead of using <code>.getPrev()</code> or <code>.getNext()</code>, try <a href="http://buildwithcraft.com/docs/templating/entrymodel#getPrevSibling"><code>.getPrevSibling()</code></a> or <a href="http://buildwithcraft.com/docs/templating/entrymodel#getNextSibling"><code>.getNextSibling()</code></a> (or their aliases <code>.prevSibling</code> and <code>.nextSibling</code>.)</p>
  
  <p>You could create prev/next links with something like this:</p>
  
  <pre><code>{% 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 %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T09:43:09.790Z
Answers.LastActivityDate: 2014-06-20T09:43:09.790Z
Answers.UserDisplayName: Stuart Whitehead
Body: <p>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.</p>
  
  <p>I've been trying this, but I can't get it not to step into D or I.</p>
  
  <pre><code>{%  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 }}
  </code></pre>
  
  <ul>
  <li>A
  <ul>
  <li>B</li>
  <li>C</li>
  <li>D
  <ul>
  <li>E</li>
  <li>F</li>
  <li>G</li>
  <li>H</li>
  </ul></li>
  </ul></li>
  <li>I
  <ul>
  <li>J</li>
  <li>K</li>
  <li>L
  <ul>
  <li>M</li>
  <li>N</li>
  <li>O</li>
  <li>P</li>
  </ul></li>
  </ul></li>
  </ul>
  
Tags: <structure>
Title: How do you page through entries in a structure?
ThreadText: # How do you page through entries in a structure?
  
  (Asked by: username_0 on 2014-06-20)
  
  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
  
  **Tags:** structure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-20. Score: 7 | Accepted answer
  
  Craft provides many helpful methods to traverse structure sections and your use case is no exception.
  
  Instead of using `.getPrev()` or `.getNext()`, try [`.getPrevSibling()`](http://buildwithcraft.com/docs/templating/entrymodel#getPrevSibling) or [`.getNextSibling()`](http://buildwithcraft.com/docs/templating/entrymodel#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 %}
  
  ```
  
  
  ---
  
  