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?

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 %}
| improve this answer | |

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.