<p>In this particular case, <code>.relatedTo(entry)</code> is not necessary. So long the entry the following code is located within is within the <code>entry</code> within the <code>source</code> the pagination will populate. Otherwise these will remain empty.</p>

<pre><code>{% set source = craft.entries.sectionId(10).first().gallery.type('gallery').first().entries %}

{% set prevEntry = entry.getPrev(source) %}
{% set nextEntry = entry.getNext(source) %}

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

CC BY-SA 3.0
2016-01-23T16:22:17.807Z
2016-01-23T16:22:17.807Z
Timothy Ingram
<p>Are you sure your <code>entry</code> variable is an entry model within your <code>source</code> ElementCriteriaModel?</p>

<p>I'd also recommend to not chain all the methods in a single expression. Getting the models one after the other and storing them into separate vars allows to add some error handling and makes debugging easier.</p>

CC BY-SA 3.0
2016-01-23T16:01:49.460Z
The `entry` variable is an entry model within my `source`. Your question helped lead me to my solution. Once I dropped `.relatedTo(entry)` from the source, the pagination worked.
Timothy Ingram
CC BY-SA 3.0
2016-01-23T10:36:16.803Z
2016-01-23T10:36:16.803Z
carlcs
<p>I have combed through similar questions, although my pagination links are not performing properly.</p>

<p>I would like to add pagination links to entries within a channel. And I would like for the pagination order to be pulled from an Entries field within a Matrix located within a Single entry.</p>

<p>So far I have:</p>

<pre><code>{% set source = craft.entries.sectionId(10).first().gallery.type('gallery').first().entries.relatedTo(entry) %}

{% set prevEntry = entry.getPrev(source) %}
{% set nextEntry = entry.getNext(source) %}

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

<p>Where SectionId(10.first() is pulling the Single entry and gallery.type('gallery').first().entries is pulling the Entries field within the Matrix.</p>

<p>Unfortunately this is producing blank Next and Previous links.</p>

<pre><code>&lt;a href=""&gt;Next: &lt;/a&gt;
&lt;a href=""&gt;Previous: &lt;/a&gt;
</code></pre>

<p>I have referred to other questions regarding params and relations, although through experimenting with different solutions I am not queuing up the correct Next and Previous entries.</p>

<p>Neither is Craft providing any error reports regarding the blank state.</p>

<p>Any help is greatly appreciated.</p>

<matrix><relations><pagination><channels><previous-next>
How do you create pagination links related to entries within a Matrix Field in a single entry?
# How do you create pagination links related to entries within a Matrix Field in a single entry?

(Asked by: username_0 on 2016-01-22)

I have combed through similar questions, although my pagination links are not performing properly.
I would like to add pagination links to entries within a channel. And I would like for the pagination order to be pulled from an Entries field within a Matrix located within a Single entry.
So far I have:
{% set source = craft.entries.sectionId(10).first().gallery.type('gallery').first().entries.relatedTo(entry) %}

{% set prevEntry = entry.getPrev(source) %}
{% set nextEntry = entry.getNext(source) %}

Next: {{ nextEntry.title }}
Previous: {{ prevEntry.title }}

Where SectionId(10.first() is pulling the Single entry and gallery.type('gallery').first().entries is pulling the Entries field within the Matrix.
Unfortunately this is producing blank Next and Previous links.
Next: 
Previous: 

I have referred to other questions regarding params and relations, although through experimenting with different solutions I am not queuing up the correct Next and Previous entries.
Neither is Craft providing any error reports regarding the blank state.
Any help is greatly appreciated.

**Tags:** matrix, relations, pagination, channels, previous-next


---

## 2 answers

### Answer by username_0 on 2016-01-23. Score: 1

In this particular case, .relatedTo(entry) is not necessary. So long the entry the following code is located within is within the entry within the source the pagination will populate. Otherwise these will remain empty.
{% set source = craft.entries.sectionId(10).first().gallery.type('gallery').first().entries %}

{% set prevEntry = entry.getPrev(source) %}
{% set nextEntry = entry.getNext(source) %}

Next: {{ nextEntry.title }}
Previous: {{ prevEntry.title }}


---

### Answer by username_1 on 2016-01-23. Score: 0

Are you sure your `entry` variable is an entry model within your `source` ElementCriteriaModel?

I'd also recommend to not chain all the methods in a single expression. Getting the models one after the other and storing them into separate vars allows to add some error handling and makes debugging easier.

> **Comments:**
> **username_0**: The `entry` variable is an entry model within my `source`. Your question helped lead me to my solution. Once I dropped `.relatedTo(entry)` from the source, the pagination worked.  

---

