<p>You would need query for these entries using the <a href="https://craftcms.com/docs/templating/elementcriteriamodel#first" rel="noreferrer"><code>first</code></a> and the <a href="https://craftcms.com/docs/templating/elementcriteriamodel#last" rel="noreferrer"><code>last</code></a> method.</p>

<pre class="lang-html prettyprint-override"><code>{% set criteria = craft.entries.section('blog').order('title asc') %}

{% set prevEntry = entry.getPrev(criteria) ?: criteria.last() %}
{% set nextEntry = entry.getNext(criteria) ?: criteria.first() %}

&lt;a href="{{ prevEntry.url }}"&gt;{{ prevEntry.title }}&lt;/a&gt;
&lt;a href="{{ nextEntry.url }}"&gt;{{ nextEntry.title }}&lt;/a&gt;
</code></pre>

CC BY-SA 3.0
2016-05-03T09:58:16.330Z
What about it if you have more then just one url? Do you need to set every field?
Justin Dekkers
CC BY-SA 3.0
2016-05-03T10:06:25.793Z
Updated the answer accordingly.
carlcs
CC BY-SA 3.0
2016-05-03T09:53:03.147Z
2016-05-03T10:03:40.827Z
2016-05-03T10:03:40.827Z
carlcs
<p>I know how to display every next entry, but is it possible when there is no next entry it displays the first one and if there isn’t a previous display the last entry?</p>

<templating><elementcriteriamodel>
Infinite getPrev and getNext?
# Infinite getPrev and getNext?

(Asked by: username_0 on 2016-05-03)

I know how to display every next entry, but is it possible when there is no next entry it displays the first one and if there isn’t a previous display the last entry?

**Tags:** templating, elementcriteriamodel

---

## 1 answers

### Answer by username_0 on 2016-05-03. Score: 9 | Accepted answer

You would need query for these entries using the first and the last method.
{% set criteria = craft.entries.section('blog').order('title asc') %}

{% set prevEntry = entry.getPrev(criteria) ?: criteria.last() %}
{% set nextEntry = entry.getNext(criteria) ?: criteria.first() %}

{{ prevEntry.title }}
{{ nextEntry.title }}

> **Comments:**
> **username_1**: What about it if you have more then just one url? Do you need to set every field?  
> **username_0**: Updated the answer accordingly.  

---

