Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T11:51:36.563Z
Answers.LastActivityDate: 2015-05-06T11:57:43.147Z
Answers.LastEditDate: 2015-05-06T11:57:43.147Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <relations><structure>
Title: Way to getNext() within the same category
ThreadText: # 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 %}<a href="{{ prevEntry.url }}">Previous</a>{% endif %}
  {% if nextEntry %}<a href="{{ nextEntry.url }}">Next</a>{% endif %}
  
  ```
  
  Or, if you prefer, a params array (same as you would pass to `craft.entries` ElementCriteriaModel):
  
  ```
  {% set params = {
      section: 'news',
      relatedTo: category,
  } %}
  
  ```
  
  
  ---
  
  