<p>To do this, you would need to use <a href="http://buildwithcraft.com/docs/templating/entrymodel#getPrev" rel="nofollow">getPrev()</a> and <a href="http://buildwithcraft.com/docs/templating/entrymodel#getNext" rel="nofollow">getNext()</a> on the related entries’ template.</p>

<p>The trick is telling getPrev() and getNext() to use the order you defined in the source entry’s Entries field.</p>

<p>So first, you will need to get that source entry. If you only have a single entry in your structure section that has one of these Entries fields, that could be as simple as this:</p>

<pre><code>{# Get the entry in the structure section that relates to `entry` %}
{% set sourceEntry = craft.entries.section('myStructureSection').relatedTo({
    targetElement: entry,
    field: 'myEntriesField'
}) %}
</code></pre>

<p>Once you have that, you can just pass its Entries field into getPrev() and getNext():</p>

<pre><code>{% set prevEntry = entry.getPrev(sourceEntry.myEntriesField) %}
{% set nextEntry = entry.getNext(sourceEntry.myEntriesField) %}

{% if prevEntry %}
    &lt;a href="{{ prevEntry.url }}"&gt;Previous: {{ prevEntry.title }}&lt;/a&gt;
{% endif %}

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

CC BY-SA 3.0
2014-06-13T23:43:54.100Z
This is close but not quite there. I'm going to hack away at it and see if I can figure out why. I might rethink the way this is setup and just use a Structure for sorting purposes instead of a relationship.
Stuart McCoy
CC BY-SA 3.0
2014-06-13T17:05:22.867Z
2014-07-14T18:42:58.343Z
2014-07-14T18:42:58.343Z
Brandon Kelly
<p>I have an entries field type associated with a structure section page. This displays the entries on this page in a particular order. When you click an entry link ti will take you to  a detailed page for more information about that entry. What I'd like to be able to do is paginate through these entries in the order set in the entries field, not just paginate through the entries in asc/desc or alphabetical order as would happen if I just paginated through the channel section that stores the entries.</p>

<p>I tried straight forward pagination as detailed in the documentation but two problems occurred. First the pagination links were created with proper beginning end and number but when clicking through them you remained on the same entry. Second, a pagination URI was appended to the URL which I don't want.</p>

<p>Is pagination even the proper approach to this problem or is there a better solution?</p>

CC BY-SA 3.0
2014-06-13T16:11:27.547Z
When you say you want to “paginate” through them, do you mean you want to list some number of them at a time (pagination), or just show links to the previous and next entries?
Brandon Kelly
CC BY-SA 3.0
2014-06-13T16:17:45.567Z
The latter. I started working through the advice below and am halfway through the solution, Just trying to figure out how to sort these by the entries field instead of relying on the order parameter.
Stuart McCoy
CC BY-SA 3.0
2014-06-13T16:38:16.240Z
Stuart, you should just change `title` in the parameters to the field you'd like your entries to be order by. (I am referring to [this answer](http://craftcms.stackexchange.com/a/58/125))
carlcs
CC BY-SA 3.0
2014-06-13T16:58:16.300Z
It doesn't appear to be that simple. I tried that first thing and got a CDbException error. Looking into relatedTo and seeing if I can maybe build this within an entries loop instead.
Stuart McCoy
CC BY-SA 3.0
2014-06-13T17:23:25.750Z
Sorry, I probably didn't read your question thoroughly. Chances are that @Brandon answer is what you are after. Deleting mine.
carlcs
CC BY-SA 3.0
2014-06-13T18:25:45.463Z
No, it definitely helped because I was barking up the wrong tree with pagination but the sort order is important and the straight up prevEntry/nextEntry wasn't enough on its own.
Stuart McCoy
<pagination><relations><previous-next><entries-field>
What's the best way to paginate through entries from an entries field type?
# What's the best way to paginate through entries from an entries field type?

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

I have an entries field type associated with a structure section page. This displays the entries on this page in a particular order. When you click an entry link ti will take you to a detailed page for more information about that entry. What I'd like to be able to do is paginate through these entries in the order set in the entries field, not just paginate through the entries in asc/desc or alphabetical order as would happen if I just paginated through the channel section that stores the entries.

I tried straight forward pagination as detailed in the documentation but two problems occurred. First the pagination links were created with proper beginning end and number but when clicking through them you remained on the same entry. Second, a pagination URI was appended to the URL which I don't want.

Is pagination even the proper approach to this problem or is there a better solution?

**Tags:** pagination, relations, previous-next, entries-field
> **Comments:**
> **username_1**: When you say you want to “paginate” through them, do you mean you want to list some number of them at a time (pagination), or just show links to the previous and next entries?  
> **username_0**: The latter. I started working through the advice below and am halfway through the solution, Just trying to figure out how to sort these by the entries field instead of relying on the order parameter.  
> **username_2**: Stuart, you should just change `title` in the parameters to the field you'd like your entries to be order by. (I am referring to [this answer](http://craftcms.stackexchange.com/a/58/125))  
> **username_0**: It doesn't appear to be that simple. I tried that first thing and got a CDbException error. Looking into relatedTo and seeing if I can maybe build this within an entries loop instead.  
> **username_2**: Sorry, I probably didn't read your question thoroughly. Chances are that @Brandon answer is what you are after. Deleting mine.  
> **username_0**: No, it definitely helped because I was barking up the wrong tree with pagination but the sort order is important and the straight up prevEntry/nextEntry wasn't enough on its own.  

---

## 1 answers

### Answer by username_1 on 2014-06-13. Score: 4 | Accepted answer

To do this, you would need to use getPrev() and getNext() on the related entries’ template.
The trick is telling getPrev() and getNext() to use the order you defined in the source entry’s Entries field.
So first, you will need to get that source entry. If you only have a single entry in your structure section that has one of these Entries fields, that could be as simple as this:
{# Get the entry in the structure section that relates to `entry` %}
{% set sourceEntry = craft.entries.section('myStructureSection').relatedTo({
    targetElement: entry,
    field: 'myEntriesField'
}) %}

Once you have that, you can just pass its Entries field into getPrev() and getNext():
{% set prevEntry = entry.getPrev(sourceEntry.myEntriesField) %}
{% set nextEntry = entry.getNext(sourceEntry.myEntriesField) %}

{% if prevEntry %}
    Previous: {{ prevEntry.title }}
{% endif %}

{% if nextEntry %}
    Next: {{ nextEntry.title }}
{% endif %}

> **Comments:**
> **username_0**: This is close but not quite there. I'm going to hack away at it and see if I can figure out why. I might rethink the way this is setup and just use a Structure for sorting purposes instead of a relationship.  

---

