<p>Based on your description, this should do it:</p>

<pre><code>{% if entry.style|length %}
&lt;aside&gt;
    &lt;h4 class="text-center"&gt;Related Posts&lt;/h4&gt;
    &lt;div class="columns"&gt;
        &lt;ul class="medium-block-grid-3"&gt;  
            {% set styleCategory = entry.style.first() %}
            {% set relatedEntries = craft.entries.section('news').relatedTo({
                targetElement: styleCategory,
                field: 'style'
            }).id('not '~entry.id) %}
            {% for relatedEntry in relatedEntries %}
                &lt;li class="text-center"&gt;&lt;a href="{{relatedEntry.url}}"&gt;{{relatedEntry.title}}&lt;/a&gt;&lt;/li&gt; 
            {% endfor %}
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/aside&gt;
{% endif %}
</code></pre>

<p>A few notes:</p>

<p>– I've wrapped the whole "Related posts" in a conditional testing if the <code>entry.style</code> categories field is not empty (<code>if entry.style|length</code>).</p>

<p>– Personal preference, but for readability's sake I find its usually a good idea to be specific/semantic with variable names (e.g. <code>styleCategory</code> instead of just <code>category</code>, <code>relatedEntries</code> instead of <code>entries</code> etc).</p>

<p>– The <code>targetElement</code> and <code>field</code> attributes for the <a href="https://craftcms.com/docs/relations" rel="nofollow"><code>relatedTo()</code></a> parameter are not required – you could just do <code>.relatedTo(styleCategory)</code>. Being specific is a minor performance win and avoids wrong results if you have multiple relations involving the same elements.</p>

<p>– The <code>id('not '~entry.id)</code> prevents the current entry from being returned</p>

CC BY-SA 3.0
2016-08-14T14:36:20.970Z
Thank you for the logic flow.  Now it works and I understand why.
Hellyar
CC BY-SA 3.0
2016-08-14T13:35:02.913Z
2016-08-14T13:35:02.913Z
Mats Mikkel Rummelhoff
<p>So, I am new.  I want to display the 1-n most recent posts in the same category as the current entry (preferably excluding the current entry) -- i.e., I want to have a section with Other Similar Posts at the bottom of an entry page. </p>

<p>I only have one Category Group = beerStyles. There are multiple categories to choose from in beerStyles. Each news entry includes a field called "style" to assign a category from beerStyles. Each entry can have only 1 category.  (Note there is no entries field in news entry, just the style field to select a category form beerStyles.)</p>

<pre><code>&lt;aside&gt;
        &lt;h4 class="text-center"&gt;Related Posts&lt;/h4&gt;
        &lt;div class="columns"&gt;
            &lt;ul class="medium-block-grid-3"&gt;  
                {% set category = craft.categories.slug('beerStyles') %}
                {% set entries = craft.entries.relatedTo(category) %}
                {% for entry in entries %}
                &lt;li class="text-center"&gt;&lt;a href="{{entry.url}}"&gt;{{entry.title}}&lt;/a&gt;&lt;/li&gt; 
                {% endfor %}
            &lt;/ul&gt;
        &lt;/div&gt;
    &lt;/aside&gt;
</code></pre>

<p>No error is thrown, but other news entries with the same category assigned are not appearing.  Nothing is appearing.  </p>

<p>Any thoughts?  And thank you in advance for your time and assistance. </p>

<p>P.S.  I know I left off the .limit(x) to limit the number of posts  I just want to get it working first. </p>

CC BY-SA 3.0
2016-08-14T01:35:11.767Z
I think you forgot to add the category group. For example I've just used:
`{% set cats = craft.categories.group('magazineCategory') %}`
Tibor Szasz
CC BY-SA 3.0
2016-08-14T01:51:58.657Z
I did try switching slug to categories.  Everything appeared.  The output was not filtered (on current entry's category.)
Hellyar
CC BY-SA 3.0
2016-08-14T02:34:27.643Z
This should be the correct:
`craft.categories.group('yourGroup').slug('beerStyles')`
Tibor Szasz
<categories>
Show Other Entries in Same Category
# Show Other Entries in Same Category

(Asked by: username_0 on 2016-08-14)

So, I am new.  I want to display the 1-n most recent posts in the same category as the current entry (preferably excluding the current entry) -- i.e., I want to have a section with Other Similar Posts at the bottom of an entry page. 
I only have one Category Group = beerStyles. There are multiple categories to choose from in beerStyles. Each news entry includes a field called "style" to assign a category from beerStyles. Each entry can have only 1 category.  (Note there is no entries field in news entry, just the style field to select a category form beerStyles.)

        Related Posts
        
              
                {% set category = craft.categories.slug('beerStyles') %}
                {% set entries = craft.entries.relatedTo(category) %}
                {% for entry in entries %}
                {{entry.title}} 
                {% endfor %}
            
        
    

No error is thrown, but other news entries with the same category assigned are not appearing.  Nothing is appearing.  
Any thoughts?  And thank you in advance for your time and assistance. 
P.S.  I know I left off the .limit(x) to limit the number of posts  I just want to get it working first.

**Tags:** categories
> **Comments:**
> **username_1**: I think you forgot to add the category group. For example I've just used: `{% set cats = craft.categories.group('magazineCategory') %}`  
> **username_0**: I did try switching slug to categories.  Everything appeared.  The output was not filtered (on current entry's category.)  
> **username_1**: This should be the correct: `craft.categories.group('yourGroup').slug('beerStyles')`  

---

## 1 answers

### Answer by username_2 on 2016-08-14. Score: 4 | Accepted answer

Based on your description, this should do it:
{% if entry.style|length %}

    Related Posts
    
          
            {% set styleCategory = entry.style.first() %}
            {% set relatedEntries = craft.entries.section('news').relatedTo({
                targetElement: styleCategory,
                field: 'style'
            }).id('not '~entry.id) %}
            {% for relatedEntry in relatedEntries %}
                {{relatedEntry.title}} 
            {% endfor %}
        
    

{% endif %}

A few notes:
– I've wrapped the whole "Related posts" in a conditional testing if the entry.style categories field is not empty (if entry.style|length).
– Personal preference, but for readability's sake I find its usually a good idea to be specific/semantic with variable names (e.g. styleCategory instead of just category, relatedEntries instead of entries etc).
– The targetElement and field attributes for the relatedTo() parameter are not required – you could just do .relatedTo(styleCategory). Being specific is a minor performance win and avoids wrong results if you have multiple relations involving the same elements.
– The id('not '~entry.id) prevents the current entry from being returned

> **Comments:**
> **username_0**: Thank you for the logic flow.  Now it works and I understand why.  

---

