<p>You can set the <code>prev.url</code> at the top of the template, for example:</p>

<pre><code>{% set criteria = {section: 'blog', order: 'postDate'} %}
{% set prev = entry.getPrev(criteria) %}
</code></pre>

<p>Add a link if <code>prev</code> is available:</p>

<pre><code>{% if prev %}
   &lt;a href="{{ prev.url }}"&gt;{{ prev.title }}&lt;/a&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-06-12T13:30:55.813Z
Sorry @Patrick, didn't see you edited your answer before I composed mine. Now pretty much identical.
carlcs
CC BY-SA 3.0
2014-06-12T12:56:25.097Z
2017-10-15T13:36:30.837Z
2017-10-15T13:36:30.837Z
Patrick Nesbitt
<p>For navigating siblings in a <code>structure</code> there's a shortcut:</p>
<pre class="lang-twig prettyprint-override"><code>{% if entry.prevSibling %}&lt;a href=&quot;{{ entry.prevSibling.url }}&quot;&gt;Previous&lt;/a&gt;{% endif %}
{% if entry.nextSibling %}&lt;a href=&quot;{{ entry.nextSibling.url }}&quot;&gt;Next&lt;/a&gt;{% endif %}
</code></pre>

CC BY-SA 4.0
2021-03-09T09:33:58.063Z
2021-03-11T10:30:13.380Z
2021-03-11T10:30:13.380Z
Tamlyn
<p>You are probably not using this within a craft.entries loop. Position it inside a loop or set custom parameters for your prev and next elements:</p>

<pre><code>{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('blog').order('title asc') %}

{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}

{# And make sure to only output the links if the element exists #}
{% if prevEntry %}&lt;a href="{{ prevEntry.url }}"&gt;Previous&lt;/a&gt;{% endif %}
{% if nextEntry %}&lt;a href="{{ nextEntry.url }}"&gt;Next&lt;/a&gt;{% endif %}
</code></pre>

CC BY-SA 3.0
2016-04-06T09:30:58.023Z
For anyone in the same position has me who has a few entries with identical post dates (both date and time are the same), for this to work properly if ordering by post date, you also need to specify the secondary sort parameter Craft uses, which, from a quick inspect of the entries section of the CMS seems to be id (ascending). So the full criteria would be `craft.entries.section(mySection).order('postDate desc, id asc')`.
Mike Vaux
CC BY-SA 4.0
2019-01-11T17:06:01.880Z
How do I get this to work in Craft 3? I can get the prev & next urls via the paginate tag but I'm stuck on how to retrieve the entry titles...
erwinheiser
CC BY-SA 3.0
2014-06-12T13:56:59.690Z
Thanks, I assumed that the `entry` already set for the URL I'm viewing would know about what came before and after.
Derek Hogue
CC BY-SA 3.0
2014-06-12T13:24:37.450Z
2014-06-12T18:34:48.250Z
2014-06-12T18:34:48.250Z
carlcs
<p>What would be the equivalent in Craft of ExpressionEngine's <a href="http://ellislab.com/expressionengine/user-guide/add-ons/channel/entry_linking.html">Next/Previous entry linking</a>? I was looking at <code>getNext()</code> and <code>getPrev()</code> (and their aliases <code>next</code> and <code>prev</code>) (via the <a href="http://buildwithcraft.com/docs/templating/entrymodel">EntryModel docs</a>), but when I try the obvious:</p>

<pre><code>&lt;a href="{{ entry.prev.url }}"&gt;Previously: {{ entry.prev.title }}&lt;/a&gt;
</code></pre>

<p>I just get the current entry's data.</p>

<p>What piece am I missing here?</p>

<pagination><navigation><entrymodel>
How to link to previous/next entries in a section?
# How to link to previous/next entries in a section?

(Asked by: username_0 on 2014-06-12)

What would be the equivalent in Craft of ExpressionEngine's Next/Previous entry linking? I was looking at getNext() and getPrev() (and their aliases next and prev) (via the EntryModel docs), but when I try the obvious:
Previously: {{ entry.prev.title }}

I just get the current entry's data.
What piece am I missing here?

**Tags:** pagination, navigation, entrymodel


---

## 3 answers

### Answer by username_2 on 2014-06-12. Score: 62 | Accepted answer

You are probably not using this within a craft.entries loop. Position it inside a loop or set custom parameters for your prev and next elements:
{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('blog').order('title asc') %}

{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}

{# And make sure to only output the links if the element exists #}
{% if prevEntry %}Previous{% endif %}
{% if nextEntry %}Next{% endif %}

> **Comments:**
> **username_0**: Thanks, I assumed that the `entry` already set for the URL I'm viewing would know about what came before and after.  
> **username_4**: For anyone in the same position has me who has a few entries with identical post dates (both date and time are the same), for this to work properly if ordering by post date, you also need to specify the secondary sort parameter Craft uses, which, from a quick inspect of the entries section of the CMS seems to be id (ascending). So the full criteria would be `craft.entries.section(mySection).order('postDate desc, id asc')`.  
> **username_5**: How do I get this to work in Craft 3? I can get the prev & next urls via the paginate tag but I'm stuck on how to retrieve the entry titles...  

---

### Answer by username_1 on 2014-06-12. Score: 20

You can set the prev.url at the top of the template, for example:
{% set criteria = {section: 'blog', order: 'postDate'} %}
{% set prev = entry.getPrev(criteria) %}

Add a link if prev is available:
{% if prev %}
   {{ prev.title }}
{% endif %}

> **Comments:**
> **username_2**: Sorry @Patrick, didn't see you edited your answer before I composed mine. Now pretty much identical.  

---

### Answer by username_3 on 2021-03-09. Score: 3

For navigating siblings in a structure there's a shortcut:
{% if entry.prevSibling %}Previous{% endif %}
{% if entry.nextSibling %}Next{% endif %}


---

