{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('nieuws').all() %}

{# Get the prev/next elements #}
{% set nextEntry = entry.getNext(params) %}

This used to work in Craft 2 in v3 I get an unknown property error. I can retrieve the prev and next links via the paginate tag but how do I retrieve the titles of the prev and next entry??


This did the trick - I'm assuming a news channel here with datestamped entries.

{% set query = craft.entries
    .id('not ' ~ entry.id)
    .limit(1) %}

{% set prevEntry = clone(query)
    .postDate('<= ' ~ entry.postDate.timestamp)
    .order('postDate desc')
    .one() %}

{% set nextEntry = clone(query)
    .postDate('>= ' ~ entry.postDate.timestamp)
    .order('postDate asc')
    .one() %}

{% if prevEntry %}
  <p><a href="{{ prevEntry.url }}">< {{ prevEntry.title }}</a></p>
{% endif %}

{% if nextEntry %}
  <p><a href="{{ nextEntry.url }}">{{ nextEntry.title }} ></a></p>
{% endif %}

Hat tip to How to get the previous or next two entries


What you did is passing array of entries into getNext method. You need to pass array of query criteria instead:

{% set criteria = {section: 'nieuws', order: 'postDate'} %}
{% set prevEntry = entry.getPrev(criteria) %}

Note that if there is no next or previous entry, getPrev or getNext will return null.

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.