<p>You're close! <code>getNext</code> and <code>getPrev</code> take an ElementCriteriaModel as a parameter:</p>

<pre><code>{% set params = craft.entries.section('news').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 %}
</code></pre>

<p>Or, if you prefer, a params array (same as you would pass to <code>craft.entries</code> ElementCriteriaModel):</p>

<pre><code>{% set params = {
    section: 'news',
    relatedTo: category,
} %}
</code></pre>

CC BY-SA 3.0
2015-05-06T11:51:36.563Z
2015-05-06T11:57:43.147Z
2015-05-06T11:57:43.147Z
carlcs
<p>I'm trying to get the next and previous entries in a structure but I only want the next or previous ones within the same category?</p>

<p>Is it possible to do something like this?</p>

<pre><code>{% set next = entry.getNext().relatedTo(category).first() %}
</code></pre>

<relations><structure>
Way to getNext() within the same category
# Way to getNext() within the same category

(Asked by: username_0 on 2015-05-06)

I'm trying to get the next and previous entries in a structure but I only want the next or previous ones within the same category?
Is it possible to do something like this?
{% set next = entry.getNext().relatedTo(category).first() %}

**Tags:** relations, structure


---

## 1 answers

### Answer by username_1 on 2015-05-06. Score: 1

You're close! getNext and getPrev take an ElementCriteriaModel as a parameter:
{% set params = craft.entries.section('news').relatedTo(category) %}

{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}

{% if prevEntry %}Previous{% endif %}
{% if nextEntry %}Next{% endif %}

Or, if you prefer, a params array (same as you would pass to craft.entries ElementCriteriaModel):
{% set params = {
    section: 'news',
    relatedTo: category,
} %}


---

