Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-03T09:58:16.330Z
Answers.Text: What about it if you have more then just one url? Do you need to set every field?
Answers.UserDisplayName: Justin Dekkers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-03T10:06:25.793Z
Answers.Text: Updated the answer accordingly.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-03T09:53:03.147Z
Answers.LastActivityDate: 2016-05-03T10:03:40.827Z
Answers.LastEditDate: 2016-05-03T10:03:40.827Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <templating><elementcriteriamodel>
Title: Infinite getPrev and getNext?
ThreadText: # 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`](https://craftcms.com/docs/templating/elementcriteriamodel#first) and the [`last`](https://craftcms.com/docs/templating/elementcriteriamodel#last) method.
  
  ```html
  {% set criteria = craft.entries.section('blog').order('title asc') %}
  
  {% set prevEntry = entry.getPrev(criteria) ?: criteria.last() %}
  {% set nextEntry = entry.getNext(criteria) ?: criteria.first() %}
  
  <a href="{{ prevEntry.url }}">{{ prevEntry.title }}</a>
  <a href="{{ nextEntry.url }}">{{ nextEntry.title }}</a>
  
  ```
  
  > **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.  
  
  ---
  
  