1
{# 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??

2

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

{% set query = craft.entries
    .section('nieuws')
    .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

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.