<p>I'm going to assume your project section is named <code>projects</code>, if it's not, replace it with you section name. </p>

<p>Try this:</p>

<pre><code>{% if nextEntry %}
    {% set nextEntryUrl = nextEntry.url %}
{% else %}
    {% set firstEntry = craft.entries.section('projects').first() %}
    {% set nextEntryUrl = firstEntry.url %}
{% endif %}

{% if prevEntry %}
    {% set prevEntryUrl = prevEntry.url %}
{% else %}
    {% set lastEntry = craft.entries.section('projects').last() %}
    {% set prevEntryUrl = lastEntry.url %}
{% endif %}

&lt;a href="{{ prevEntryUrl }}"&gt;Prev Project&lt;/a&gt;
&lt;a href="{{ nextEntryUrl }}"&gt;Next Project&lt;/a&gt;
</code></pre>

CC BY-SA 3.0
2015-07-04T22:20:24.123Z
2015-07-04T22:20:24.123Z
André Elvan
<p>Could you do something like (untested)</p>

<pre><code>{% set nextUrl = nextEntry is defined and nextEntry ? nextEntry.url : url('portfolio/root') %}
&lt;a href="{{ nextUrl }}"&gt;Next page&lt;/a&gt;
</code></pre>

<p>Or, for probably better usability </p>

<pre><code> {% if nextEntry %}
  &lt;a href="{{ nextEntry.url }}"&gt;Next Project&lt;/a&gt;
 {% else %}
   &lt;a href="{{ url('portfolio/root') }}"&gt;back to start&lt;/a&gt;
 {% endif %}
</code></pre>

CC BY-SA 3.0
2015-07-04T08:27:56.250Z
2015-07-04T08:27:56.250Z
Alec Ritson
<p>I've got a basic portfolio website which has "prev project" and "next project" buttons on each entry detail page. I'd like for when you reach the last project for the "next project" button to simply link back to the first instead of simply not appearing at all.</p>

<p>Any idea how this could be done? Thanks so much in advance.</p>

<pre><code> {% if nextEntry %}&lt;a href="{{ nextEntry.url }}"&gt;Prev Project&lt;/a&gt;{% endif %}
 {% if prevEntry %}&lt;a href="{{ prevEntry.url }}"&gt;Next Project&lt;/a&gt;{% endif %}
</code></pre>

<entries>
How to make next/prev links for entries circular/endless
# How to make next/prev links for entries circular/endless

(Asked by: username_0 on 2015-07-04)

I've got a basic portfolio website which has "prev project" and "next project" buttons on each entry detail page. I'd like for when you reach the last project for the "next project" button to simply link back to the first instead of simply not appearing at all.
Any idea how this could be done? Thanks so much in advance.
 {% if nextEntry %}Prev Project{% endif %}
 {% if prevEntry %}Next Project{% endif %}

**Tags:** entries


---

## 2 answers

### Answer by username_1 on 2015-07-04. Score: 7

I'm going to assume your project section is named projects, if it's not, replace it with you section name. 
Try this:
{% if nextEntry %}
    {% set nextEntryUrl = nextEntry.url %}
{% else %}
    {% set firstEntry = craft.entries.section('projects').first() %}
    {% set nextEntryUrl = firstEntry.url %}
{% endif %}

{% if prevEntry %}
    {% set prevEntryUrl = prevEntry.url %}
{% else %}
    {% set lastEntry = craft.entries.section('projects').last() %}
    {% set prevEntryUrl = lastEntry.url %}
{% endif %}

Prev Project
Next Project


---

### Answer by username_2 on 2015-07-04. Score: 2

Could you do something like (untested)
{% set nextUrl = nextEntry is defined and nextEntry ? nextEntry.url : url('portfolio/root') %}
Next page

Or, for probably better usability 
 {% if nextEntry %}
  Next Project
 {% else %}
   back to start
 {% endif %}


---

