The examples I have seen to link to previous and next entry all seem to be for sections. I want to get the previous and next category.
My category handler is called 'media'.
So I might have entries in this category such as : Time Life People
When viewing the entry 'Life', I want to be able to go back to Time (Previous) or to People (Next). Again, these entries are entries in my category.
I tried:
{% set params = craft.entries.section('media').relatedTo(category) %}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{% if prevEntry %}<a href="{{ prevEntry.url }}">Previous</a>{% endif %}
{% if nextEntry %}<a href="{{ nextEntry.url }}">Next</a>{% endif %}
That didn't work, so I also tried:
{% set category = entry.category.first() %}
{% set params = craft.entries.section('media').order('title asc').relatedTo(category) %}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{% if nextEntry %}
{% set nextEntryUrl = nextEntry.url %}
{% else %}
{% set firstEntry = craft.entries.section('media').first() %}
{% set nextEntryUrl = firstEntry.url %}
{% endif %}
{% if prevEntry %}
{% set prevEntryUrl = prevEntry.url %}
{% else %}
{% set lastEntry = craft.entries.section('media').last() %}
{% set prevEntryUrl = lastEntry.url %}
{% endif %}
But also no good.
category
is a valid CategoryModel, andentry
belongs to a section with the handle"media"
, your first example looks legit. In other words, this is pretty much impossible to answer. Maybe share your entire template (as a Github gist, if its big)?