Answers.Body: <p>Try this</p>
  
  <p>// Assuming you have named portfolio group for 2D and 3D as portfolio</p>
  
  <p>// .first() if craft2, .one() if craft3</p>
  
  <pre><code>{% set category = craft.categories.group('portfolio').title('2D').first() %}
  {% set params = craft.entries({
     section: 'portfolio',
     relatedTo: category,
     orderBy: 'postDate desc',
     limit: 10
   }) %}
  </code></pre>
  
  <p>Ref: <a href="https://docs.craftcms.com/v3/dev/element-queries/category-queries.html#example" rel="nofollow noreferrer">https://docs.craftcms.com/v3/dev/element-queries/category-queries.html#example</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-11T03:24:30.127Z
Answers.LastActivityDate: 2019-12-11T03:32:22.510Z
Answers.LastEditDate: 2019-12-11T03:32:22.510Z
Answers.UserDisplayName: ScriptDev
Body: <p>I have portfolio section that has a ‘portfolio’ category attached to it, which has categories ‘2D’ and ‘3D’.</p>
  
  <p>There are 3 templates: </p>
  
  <ol>
  <li>The index template shows a list of all the entries in the portfolio 
  section. </li>
  <li>The categories template shows the entries within a specific category.</li>
  <li>The entry template shows a single entry.</li>
  </ol>
  
  <p>On the index page (/portfolio) you can click on 'All', '2D' and '3D' whereby 'All' takes you the index page, and 2D and 3D lead to /portfolio/2D and 3D (the categories template). Click on any item in the list and you go to the entry page.</p>
  
  <p>On the entry template, I have a simple ‘previous entry’ and ‘next entry’  browsing navigation, using:</p>
  
  <pre><code>{% set params = {section: 'portfolio', orderBy: 'postDate desc', limit: null} %}
  {% set entry_prev = entry.getPrev(params) %}
  {% set entry_next = entry.getNext(params) %}
  </code></pre>
  
  <p>The thing is, this navigation always browses through all of the entries, regardless of what category an entry is in. And that's fine when you've reached the page from the index page, where all of the entries are listed. But I’m trying to make it so when you click an entry on the categories page, and you are then taken to this entry page, the browsing navigation (previous and next entry) takes into account what category you’re in. I use a simple cookie or getQuery() to set and get this information. That way, when you've clicked on an entry in the list with 2D items, you don't get entries from other categories in the prev/next navigation, but when you've clicked on the same item on the index page, you do get to navigate through all of the entries.</p>
  
  <p>I’ve tried:</p>
  
  <pre><code>{% set params = craft.entries.section('portfolio').relatedTo('2d').orderBy('postDate desc').limit(10).all() %}
  </code></pre>
  
  <p>But this does not work: the navigation still includes entries that do not have the 2d category.</p>
  
  <p>Anyone have any idea how to achieve this?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-11T00:04:26.873Z
Comments.Text: Is this on Craft 2?
Comments.UserDisplayName: Oli
Tags: <categories><category><previous-next>
Title: In entry.getPrev/Next navigation, show entries from a specific category only
ThreadText: # In entry.getPrev/Next navigation, show entries from a specific category only
  
  (Asked by: username_0 on 2019-12-10)
  
  I have portfolio section that has a ‘portfolio’ category attached to it, which has categories ‘2D’ and ‘3D’.
  
  There are 3 templates:
  
  1. The index template shows a list of all the entries in the portfolio
     section.
  2. The categories template shows the entries within a specific category.
  3. The entry template shows a single entry.
  
  On the index page (/portfolio) you can click on 'All', '2D' and '3D' whereby 'All' takes you the index page, and 2D and 3D lead to /portfolio/2D and 3D (the categories template). Click on any item in the list and you go to the entry page.
  
  On the entry template, I have a simple ‘previous entry’ and ‘next entry’ browsing navigation, using:
  
  ```
  {% set params = {section: 'portfolio', orderBy: 'postDate desc', limit: null} %}
  {% set entry_prev = entry.getPrev(params) %}
  {% set entry_next = entry.getNext(params) %}
  
  ```
  
  The thing is, this navigation always browses through all of the entries, regardless of what category an entry is in. And that's fine when you've reached the page from the index page, where all of the entries are listed. But I’m trying to make it so when you click an entry on the categories page, and you are then taken to this entry page, the browsing navigation (previous and next entry) takes into account what category you’re in. I use a simple cookie or getQuery() to set and get this information. That way, when you've clicked on an entry in the list with 2D items, you don't get entries from other categories in the prev/next navigation, but when you've clicked on the same item on the index page, you do get to navigate through all of the entries.
  
  I’ve tried:
  
  ```
  {% set params = craft.entries.section('portfolio').relatedTo('2d').orderBy('postDate desc').limit(10).all() %}
  
  ```
  
  But this does not work: the navigation still includes entries that do not have the 2d category.
  
  Anyone have any idea how to achieve this?
  
  **Tags:** categories, category, previous-next
  
  > **Comments:**
  > **username_1**: Is this on Craft 2?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-12-11. Score: 0 | Accepted answer
  
  Try this
  
  // Assuming you have named portfolio group for 2D and 3D as portfolio
  
  // .first() if craft2, .one() if craft3
  
  ```
  {% set category = craft.categories.group('portfolio').title('2D').first() %}
  {% set params = craft.entries({
     section: 'portfolio',
     relatedTo: category,
     orderBy: 'postDate desc',
     limit: 10
   }) %}
  
  ```
  
  Ref: <https://docs.craftcms.com/v3/dev/element-queries/category-queries.html#example>
  
  
  ---
  
  