<p>By far, the easiest way to do this is to use the <a href="https://craftcms.com/docs/templating/nav#showing-children" rel="nofollow"><code>{% children %}</code></a> tag which is available inside a <code>{% nav %}{% endnav %}</code> tag pair, i.e. something like this:</p>

<pre><code>&lt;ul&gt;
{% nav category in craft.categories.group('products') %}
    &lt;li&gt;
      &lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;a&gt;
      {% ifchildren %}
        &lt;ul&gt;
            {% children %}
        &lt;/ul&gt;
      {% endifchildren %}
    &lt;/li&gt;
{% endnav %}
&lt;/ul&gt;
</code></pre>

<p>Note: The above will print a recursive, unordered list of all your top level <code>product</code> categories (i.e. "Akana", "Tama" etc) and their children.</p>

<p>In your current code, you won't actually be able to use the <code>{% children %}</code>, because you have a <code>slug('akana')</code> parameter on your <code>craft.categories</code> query for some reason. Using the <code>slug()</code> parameter means that Craft will <em>only pull categories with that particular slug</em> – in other words, the child category "Ona" won't be returned by your query and the <code>{% children %}</code> tag will output nothing.</p>

<p>If you have to use the <code>slug</code> parameter, there's no real use to the `{% nav %} tag (it's designed for recursive, hierarchical lists).</p>

<p>For a more "manual" approach, you can also get to a categories children by doing something like this:</p>

<pre><code>{% set category = craft.categories.group('products').slug('akana').first() %}
&lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;
{% set children = category.children %}
{% for child in children %}
    &lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>One gotcha to note is that <code>category.children</code> will pull all your category's children, from all levels. To get children for different levels, you can use the <code>level</code> parameter:</p>

<pre><code>{% set childrenA = category.children.level(2) %}
{% set childrenB = category.children.level(3) %)    
</code></pre>

CC BY-SA 3.0
2016-08-05T09:02:20.387Z
2016-08-05T09:02:20.387Z
Mats Mikkel Rummelhoff
<p>So I have a categories with sub categories. </p>

<pre><code>Anakena (Wine Brand Name)
-Ona (Wine line)

--product one
--product two

-Tama (Wine Line)

--product one
--product two
</code></pre>

<p>Im trying to make links to the specific lines. So I want to add Anakena under a field, and have it display an ul of Ona, Tama, etc. all the subcategories within Anakena. Once I click on this link, will take me to the category page with all of Ona's produtcs, etc.. </p>

<pre><code>{% nav category in craft.categories.group('products').slug('anakena') %}
   &lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;a&gt;
{% endnav %}
</code></pre>

<p>With this it gives me the main category, Anakena, how can I display the child categories assigned to Anakena.? </p>

<p>Thanks</p>

CC BY-SA 3.0
2016-08-07T07:04:57.257Z
Great,! 
Thanks Mats.. One more thing now, Is there a way to replace the .slug name with a user defined something.? each entry will have a different slug, can I have the name filled by an entry.? 

`{% set category = craft.categories.group('products').slug('{{ user defines entry?? }}').first() %}`

Thanks
fidel
CC BY-SA 3.0
2016-08-07T10:34:52.620Z
Sure, just do `{% set category = craft.categories.group('products').slug(entry.someCustomField) %}`. Don't echo the variable inside the `.slug()` parameter, i.e. don't use `{{ }}`.
Mats Mikkel Rummelhoff
<category>
Category listing.
# Category listing.

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

So I have a categories with sub categories. 
Anakena (Wine Brand Name)
-Ona (Wine line)

--product one
--product two

-Tama (Wine Line)

--product one
--product two

Im trying to make links to the specific lines. So I want to add Anakena under a field, and have it display an ul of Ona, Tama, etc. all the subcategories within Anakena. Once I click on this link, will take me to the category page with all of Ona's produtcs, etc.. 
{% nav category in craft.categories.group('products').slug('anakena') %}
   {{ category.title }}
{% endnav %}

With this it gives me the main category, Anakena, how can I display the child categories assigned to Anakena.? 
Thanks

**Tags:** category
> **Comments:**
> **username_0**: Great,!  Thanks Mats.. One more thing now, Is there a way to replace the .slug name with a user defined something.? each entry will have a different slug, can I have the name filled by an entry.?   `{% set category = craft.categories.group('products').slug('{{ user defines entry?? }}').first() %}`  Thanks  
> **username_1**: Sure, just do `{% set category = craft.categories.group('products').slug(entry.someCustomField) %}`. Don't echo the variable inside the `.slug()` parameter, i.e. don't use `{{ }}`.  

---

## 1 answers

### Answer by username_1 on 2016-08-05. Score: 1

By far, the easiest way to do this is to use the {% children %} tag which is available inside a {% nav %}{% endnav %} tag pair, i.e. something like this:

{% nav category in craft.categories.group('products') %}
    
      {{ category.title }}
      {% ifchildren %}
        
            {% children %}
        
      {% endifchildren %}
    
{% endnav %}


Note: The above will print a recursive, unordered list of all your top level product categories (i.e. "Akana", "Tama" etc) and their children.
In your current code, you won't actually be able to use the {% children %}, because you have a slug('akana') parameter on your craft.categories query for some reason. Using the slug() parameter means that Craft will only pull categories with that particular slug – in other words, the child category "Ona" won't be returned by your query and the {% children %} tag will output nothing.
If you have to use the slug parameter, there's no real use to the `{% nav %} tag (it's designed for recursive, hierarchical lists).
For a more "manual" approach, you can also get to a categories children by doing something like this:
{% set category = craft.categories.group('products').slug('akana').first() %}
{{ category.title }}
{% set children = category.children %}
{% for child in children %}
    {{ category.title }}
{% endfor %}

One gotcha to note is that category.children will pull all your category's children, from all levels. To get children for different levels, you can use the level parameter:
{% set childrenA = category.children.level(2) %}
{% set childrenB = category.children.level(3) %)


---

