<p>I would use the <a href="http://buildwithcraft.com/docs/templating/filters#without" rel="nofollow">without filter</a> and <a href="http://buildwithcraft.com/docs/relations" rel="nofollow">relations</a> for this.</p>

<pre><code>{# starting points #}
{% set externalCategory = craft.categories.slug('external-content').first() %}
{% set allEntries = craft.entries.section('webdev').find() %}

{# create the arrays/objects you need #}
{% set externalEntries = craft.entries.section('webdev').relatedTo(externalCategory).find() %}
{% set otherEntries = allEntries|without(externalEntries) %}
</code></pre>

<p>then use the usual for loops for each array / object you have created. That way, you only need to define your external-content category, all the rest is automatic, regardless of the number of other categories you have.</p>

<p>Depending on the number of entries you have and the kind of traffic you get, you might want to consider <a href="http://buildwithcraft.com/docs/templating/cache" rel="nofollow">caching</a> this.</p>

CC BY-SA 3.0
2014-08-20T08:49:54.203Z
2014-08-20T08:49:54.203Z
Jérôme Coupé
<p>I've got a section called 'web development' and there are four categories that apply to it. Three can be grouped together as 'original content' and one is a link list to external third party content.</p>

<p>I'd like to split my entry archive list such that one group lists all entries in the Web Development section that <em>don't</em> belong to the 'external' category (there will only ever be one 'external' category, but I may make new categories that apply to 'original content' so I don't want to hard-code the categories).</p>

<p>After that I'd like to loop through again but only listing entries that <em>do</em> belong to that 'external' category. For each entry I'd like to spit out which category it belongs to as well as the entry title and date.</p>

<p>I can't wrap my head around how to do this, I'm not sure I'm groking how to use relations. Or would I be better to create nested categories rather than trying to group them 'after the fact'?</p>

<p>EDIT: went with making categories and sub categories, but still can't get things to work!</p>

<pre><code>{% set originalContentCategory   = craft.categories.slug('original-content').find() %}
{% set originalContentCategories = craft.categories.group('global').descendantOf(originalContentCategory).find() %}
{% for category in originalContentCategories %}
    &lt;h3&gt;{{ category.title }}&lt;/h3&gt;
    {{ category.synopsis }}
{% endfor %}
</code></pre>

<p>This is listing all categories in the group, including the 'original-content' category itself. What am I doing wrong?</p>

CC BY-SA 3.0
2014-08-19T22:10:30.750Z
Replace `find()` with `first()` to save one category in your `originalContentCategory` var instead of an array.
carlcs
<categories>
List all entries in a section filtered by given category groups
# List all entries in a section filtered by given category groups

(Asked by: username_0 on 2014-08-19)

I've got a section called 'web development' and there are four categories that apply to it. Three can be grouped together as 'original content' and one is a link list to external third party content.
I'd like to split my entry archive list such that one group lists all entries in the Web Development section that don't belong to the 'external' category (there will only ever be one 'external' category, but I may make new categories that apply to 'original content' so I don't want to hard-code the categories).
After that I'd like to loop through again but only listing entries that do belong to that 'external' category. For each entry I'd like to spit out which category it belongs to as well as the entry title and date.
I can't wrap my head around how to do this, I'm not sure I'm groking how to use relations. Or would I be better to create nested categories rather than trying to group them 'after the fact'?
EDIT: went with making categories and sub categories, but still can't get things to work!
{% set originalContentCategory   = craft.categories.slug('original-content').find() %}
{% set originalContentCategories = craft.categories.group('global').descendantOf(originalContentCategory).find() %}
{% for category in originalContentCategories %}
    {{ category.title }}
    {{ category.synopsis }}
{% endfor %}

This is listing all categories in the group, including the 'original-content' category itself. What am I doing wrong?

**Tags:** categories
> **Comments:**
> **username_1**: Replace `find()` with `first()` to save one category in your `originalContentCategory` var instead of an array.  

---

## 1 answers

### Answer by username_2 on 2014-08-20. Score: 4 | Accepted answer

I would use the without filter and relations for this.
{# starting points #}
{% set externalCategory = craft.categories.slug('external-content').first() %}
{% set allEntries = craft.entries.section('webdev').find() %}

{# create the arrays/objects you need #}
{% set externalEntries = craft.entries.section('webdev').relatedTo(externalCategory).find() %}
{% set otherEntries = allEntries|without(externalEntries) %}

then use the usual for loops for each array / object you have created. That way, you only need to define your external-content category, all the rest is automatic, regardless of the number of other categories you have.
Depending on the number of entries you have and the kind of traffic you get, you might want to consider caching this.


---

