0

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) %}

<a href="{{ nextEntry.url }}">Next: {{ nextEntry.title }}</a>
<a href="{{ prevEntry.url }}">Previous: {{ prevEntry.title }}</a>

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.

<a href="">Next: </a>
<a href="">Previous: </a>

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.

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) %}

<a href="{{ nextEntry.url }}">Next: {{ nextEntry.title }}</a>
<a href="{{ prevEntry.url }}">Previous: {{ prevEntry.title }}</a>
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.

  • 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 Jan 23 '16 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.