Display the next and previous category 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 %}&lt;a href="{{ prevEntry.url }}"&gt;Previous&lt;/a&gt;{% endif %}
{% if nextEntry %}&lt;a href="{{ nextEntry.url }}"&gt;Next&lt;/a&gt;{% 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.
Based on your example and description, it's a bit hard to tell whether you are dealing with a category template or an entry template, because in your description you say that the category handle is called 'media', but in the example you are grabbing entries in the section called 'media'.

Assuming you are on a category template (i.e. trying to create a category index page for example), then you should be able to just grab the current category from the 'category' variable (provided by craft), entries related to that category using relatedTo(category), and the next and previous categories from category.nextSibling and category.previousSibling (or category.next and category.previous depending on whether your categories are hierarchical). If so, then the following should work (not tested):

{# category template #}

{% set prevCategory = category.prevSibling %}
{% set nextCategory = category.nextSibling %}
{% set entries = craft.entries('mySection').relatedTo(category) %}

&lt;h1&gt;{{ category.title }}&lt;/h1&gt;
&lt;section class="category-index"&gt;
    {% for entry in entries %}
        &lt;article&gt;
            &lt;h2&gt;{{ entry.title }}&lt;/h2&gt;
            &lt;p&gt;...&lt;/p&gt;
        &lt;/article&gt;
    {% endfor %}
&lt;/section&gt;

{% if prevCategory %}&lt;a href="{{ prevCategory.url }}"&gt;Previous&lt;/a&gt; {% endif %}{% if nextCategory %}&lt;a href="{{ nextCategory.url }}"&gt;Next&lt;/a&gt;{% endif %}


If you are dealing with an entry template (i.e. an entry detail page), then you may need to clarify the question a bit.