4

As an extension of this question How to link to previous/next entries in a section?

If my page is set to automatically provide a entry var in my template. And I can simply access a field like this

entry.title

Which means I don't need to do something like this

{% set entry = craft.entries.section('blog').first() %}

If I want to get the next entry and previous entry based on this entry's entry type. Is it possible?

Hs Tung
  • 367
  • 2
  • 12

1 Answers1

7

No, you still have to set the parameters by your own:

{# Get this entry's entry type #}
{% set type = entry.getType() %}

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

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

{# And make sure to only output the links if the element exists #}
{% if prevEntry %}<a href="{{ prevEntry.url }}">Previous</a>{% endif %}
{% if nextEntry %}<a href="{{ nextEntry.url }}">Next</a>{% endif %}
carlcs
  • 36,220
  • 5
  • 62
  • 139