Answers.Body: <p>Check out the documentation for <a href="http://buildwithcraft.com/docs/templating/craft.categories">craft.categories</a> which should do what you need. In this example, I assume that 'landing pages' are the same as your level 1 categories, in which case you don't need to deal with the entries at all:</p>
  
  <pre><code>{% set categories = craft.categories.group('navCategories') %}
  
  &lt;ul id="nav"&gt;
      {# using 'nav' and 'children' will create a recursive loop #}
      {% nav category in categories %}
          &lt;li&gt;
              {% if category.level == 1 %}
                  &lt;a href="{{ entry.url }}" class="{{ category.slug }}" style="border-color: {{ category.supplierColour }}; color:{{ category.supplierColour }};" &gt;{{ category.title }}&lt;/a&gt;
              {% else %}
                  &lt;a href="{{ entry.url }}" class="{{ category.slug }}"&gt;{{ category.title }}&lt;/a&gt;
              {% endif %}
              {% ifchildren %}
                  &lt;div class="sub{{ category.level }} {{ category.slug }}"&gt;
                      &lt;ul&gt;
                          {% children %}
                      &lt;/ul&gt;
                  &lt;/div&gt;
              {% endifchildren %}
          &lt;/li&gt;
      {% endnav %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>If you only want a certain number of levels then you can use a level filter. I.e:</p>
  
  <pre><code>{% set categories = craft.categories.group('navCategories').level('&lt; 3') %}
  </code></pre>
  
  <p><strong>Update:</strong> If level 1 categories are not the same as your landing pages then you can access the category through <code>entry.category.first</code>, and then category decendants using: <code>{% for category in category.descendants %}...{% endfor %}</code> or <code>{% nav category in category.descendants %}...{% endnav %}</code> using the recursive method above.</p>
  
  <pre><code>&lt;ul id="nav"&gt;
      {% set entries = craft.entries.section('landingPages') %}
      {% for entry in entries %}
          {% set category = entry.category.first %}
          &lt;li&gt;
              &lt;a href="{{ entry.url }}" class="{{ category.slug }}" style="border-color: {{ category.supplierColour }}; color:{{ category.supplierColour }};" &gt;{{ entry.title }}&lt;/a&gt;
              &lt;ul class="sub {{ category.slug }}"&gt;
                  {# using 'nav' and 'children' will create a recursive loop, if more levels are needed #}
                  {% nav category in category.descendants %}
                      &lt;li&gt;
                          &lt;a href="{{ category.url }}" title="{{ category.title }}"&gt;{{ category.title }}&lt;/a&gt;
                          {% ifchildren %}
                              &lt;ul class="sub{{ category.level }}"&gt;
                                  {% children %}
                              &lt;/ul&gt;
                          {% endifchildren %}
                      &lt;/li&gt;
                  {% endnav %}
              &lt;/ul&gt;
          &lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>As a side-note: Keep in mind that you can also define css dynamically within the loop rather than defining it on the elements directly, if you wanted to.</p>
  
  <pre><code>{% set css %}
      a.{{ category.slug }} { 
          border-color: {{ category.supplierColour }}; 
          color:{{ category.supplierColour }}; 
      } 
  {% endset %}
  {% includeCss css %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-30T15:48:24.203Z
Answers.Text: If I was just looking for categories that would be easy.
  
  The issue is there are "Landing Pages" which act as a window into each category. The Landing Page is then associated with a category which pulls in things like the category logo, colour.
  
  What I need is for the navigation to list out the entries in the "Landing Page" section, then find which category they are associated with... and then list out all children of that category.
  
  Hope that makes sense.
  
  Here is the URL to the development site.
  
  http://cicadaretail.neondigital.com/
Answers.UserDisplayName: Dominic Leonard
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-30T16:37:50.453Z
Answers.Text: That's why I mentioned the second part. I figured that you could put the two together yourself. But I have updated the answer with a full example.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-30T16:46:08.050Z
Answers.Text: Another thing to mention is that categories can have their own url and template files (see the Docs link @Douglas provided). In this case it could make sense to delete the "Landing Pages" section altogether and instead use the category group not only for the navigation (first part of this nice answer) but also for the "Landing Pages" content.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-30T16:57:10.237Z
Answers.Text: [Structures](http://buildwithcraft.com/docs/sections-and-entries) and [Entry Types](http://buildwithcraft.com/help/entry-type-templates) also work great for this as well, which you can also [build nav from](http://buildwithcraft.com/help/structure-nav).
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-30T15:09:21.470Z
Answers.LastActivityDate: 2014-10-30T16:40:44.020Z
Answers.LastEditDate: 2014-10-30T16:40:44.020Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I've been scratching my head over this for awhile and I can't seem to solve it. </p>
  
  <p>What I'm after is the following.</p>
  
  <p>I have various categories with numerous sub categories. I'd like to be able to display the sub categories of a category that is related to an entry which is how my navigation  is set up.</p>
  
  <p>The code at the moment look like this...</p>
  
  <pre><code>{% set entries = craft.entries.find({ section: 'landingPages' }) %}
     {% for entry in entries %}
         &lt;li&gt;&lt;a href="{{ entry.url }}" class="{% set colour = entry.category.find() %}{% for category in colour %}{{ category.slug|striptags }}{% endfor %}" {% set colourTwo = entry.category.find() %}
             {% for category in colourTwo %} style="border-color: {{ category.supplierColour }}; color:{{ category.supplierColour }};" {% endfor %}&gt;{{ entry.title }}&lt;/a&gt;
             &lt;div class="sub {% set sub = entry.category.find() %}{% for category in sub %}{{ category.slug|striptags }}{% endfor %}"&gt;
             {% set drop = entry.category.find({ }) %}
                 &lt;ul&gt;
                 {% for category in drop %}
                    &lt;li&gt;&lt;a href="{{ category.url }}" title="{{ category.title }}"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
                 {% endfor %}
                 &lt;/ul&gt;
             &lt;/div&gt;
          &lt;/li&gt;
      {% endfor %}
  </code></pre>
  
  <p>At the moment it's just generating the category which is selected within the entry, i've tried various variations on descendant commands and nothing seems to work.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-30T05:29:28.293Z
Comments.Text: I am not exactly sure what you are trying to do. Are you trying to get the children of the related category in the natural category heirarchy? or are you trying to get descendent categories that are also assigned to the entry?
Comments.UserDisplayName: Douglas McDonald
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-30T05:30:18.073Z
Comments.Text: You also seem to be doing a lot of extra work here that is not needed. If your initial entry only has one category assigned (which I assume from the above code that it does) then you can simply use: `{% set category = entry.category.first %}` and then access all of your category fields using `{{ category.slug }}`, `{{ category.title }}`,`{{ category.colour }}`, etc. etc. You do not need to loop through categories every time you want to grab a field value.
Comments.UserDisplayName: Douglas McDonald
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-30T09:05:45.013Z
Comments.Text: Cheers Douglas.
  
  Yeah i'm not the most efficient in my twigging.
  
  And yes i'm trying to get the children on the related category.
Comments.UserDisplayName: Dominic Leonard
Tags: <categories><relations>
Title: Listing Sub Categories of a Category related to an entry
ThreadText: # Listing Sub Categories of a Category related to an entry
  
  (Asked by: username_0 on 2014-10-29)
  
  I've been scratching my head over this for awhile and I can't seem to solve it.
  
  What I'm after is the following.
  
  I have various categories with numerous sub categories. I'd like to be able to display the sub categories of a category that is related to an entry which is how my navigation is set up.
  
  The code at the moment look like this...
  
  ```
  {% set entries = craft.entries.find({ section: 'landingPages' }) %}
     {% for entry in entries %}
         <li><a href="{{ entry.url }}" class="{% set colour = entry.category.find() %}{% for category in colour %}{{ category.slug|striptags }}{% endfor %}" {% set colourTwo = entry.category.find() %}
             {% for category in colourTwo %} style="border-color: {{ category.supplierColour }}; color:{{ category.supplierColour }};" {% endfor %}>{{ entry.title }}</a>
             <div class="sub {% set sub = entry.category.find() %}{% for category in sub %}{{ category.slug|striptags }}{% endfor %}">
             {% set drop = entry.category.find({ }) %}
                 <ul>
                 {% for category in drop %}
                    <li><a href="{{ category.url }}" title="{{ category.title }}">{{ category.title }}</a></li>
                 {% endfor %}
                 </ul>
             </div>
          </li>
      {% endfor %}
  
  ```
  
  At the moment it's just generating the category which is selected within the entry, i've tried various variations on descendant commands and nothing seems to work.
  
  Any help would be greatly appreciated.
  
  **Tags:** categories, relations
  
  > **Comments:**
  > **username_1**: I am not exactly sure what you are trying to do. Are you trying to get the children of the related category in the natural category heirarchy? or are you trying to get descendent categories that are also assigned to the entry?  
  > **username_1**: You also seem to be doing a lot of extra work here that is not needed. If your initial entry only has one category assigned (which I assume from the above code that it does) then you can simply use: `{% set category = entry.category.first %}` and then access all of your category fields using `{{ category.slug }}`, `{{ category.title }}`,`{{ category.colour }}`, etc. etc. You do not need to loop through categories every time you want to grab a field value.  
  > **username_0**: Cheers username_1.  Yeah i'm not the most efficient in my twigging.  And yes i'm trying to get the children on the related category.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-10-30. Score: 6 | Accepted answer
  
  Check out the documentation for [craft.categories](http://buildwithcraft.com/docs/templating/craft.categories) which should do what you need. In this example, I assume that 'landing pages' are the same as your level 1 categories, in which case you don't need to deal with the entries at all:
  
  ```
  {% set categories = craft.categories.group('navCategories') %}
  
  <ul id="nav">
      {# using 'nav' and 'children' will create a recursive loop #}
      {% nav category in categories %}
          <li>
              {% if category.level == 1 %}
                  <a href="{{ entry.url }}" class="{{ category.slug }}" style="border-color: {{ category.supplierColour }}; color:{{ category.supplierColour }};" >{{ category.title }}</a>
              {% else %}
                  <a href="{{ entry.url }}" class="{{ category.slug }}">{{ category.title }}</a>
              {% endif %}
              {% ifchildren %}
                  <div class="sub{{ category.level }} {{ category.slug }}">
                      <ul>
                          {% children %}
                      </ul>
                  </div>
              {% endifchildren %}
          </li>
      {% endnav %}
  </ul>
  
  ```
  
  If you only want a certain number of levels then you can use a level filter. I.e:
  
  ```
  {% set categories = craft.categories.group('navCategories').level('< 3') %}
  
  ```
  
  **Update:** If level 1 categories are not the same as your landing pages then you can access the category through `entry.category.first`, and then category decendants using: `{% for category in category.descendants %}...{% endfor %}` or `{% nav category in category.descendants %}...{% endnav %}` using the recursive method above.
  
  ```
  <ul id="nav">
      {% set entries = craft.entries.section('landingPages') %}
      {% for entry in entries %}
          {% set category = entry.category.first %}
          <li>
              <a href="{{ entry.url }}" class="{{ category.slug }}" style="border-color: {{ category.supplierColour }}; color:{{ category.supplierColour }};" >{{ entry.title }}</a>
              <ul class="sub {{ category.slug }}">
                  {# using 'nav' and 'children' will create a recursive loop, if more levels are needed #}
                  {% nav category in category.descendants %}
                      <li>
                          <a href="{{ category.url }}" title="{{ category.title }}">{{ category.title }}</a>
                          {% ifchildren %}
                              <ul class="sub{{ category.level }}">
                                  {% children %}
                              </ul>
                          {% endifchildren %}
                      </li>
                  {% endnav %}
              </ul>
          </li>
      {% endfor %}
  </ul>
  
  ```
  
  As a side-note: Keep in mind that you can also define css dynamically within the loop rather than defining it on the elements directly, if you wanted to.
  
  ```
  {% set css %}
      a.{{ category.slug }} { 
          border-color: {{ category.supplierColour }}; 
          color:{{ category.supplierColour }}; 
      } 
  {% endset %}
  {% includeCss css %}
  
  ```
  
  > **Comments:**
  > **username_0**: If I was just looking for categories that would be easy.  The issue is there are "Landing Pages" which act as a window into each category. The Landing Page is then associated with a category which pulls in things like the category logo, colour.  What I need is for the navigation to list out the entries in the "Landing Page" section, then find which category they are associated with... and then list out all children of that category.  Hope that makes sense.  Here is the URL to the development site.  http://cicadaretail.neondigital.com/  
  > **username_1**: That's why I mentioned the second part. I figured that you could put the two together yourself. But I have updated the answer with a full example.  
  > **username_2**: Another thing to mention is that categories can have their own url and template files (see the Docs link @username_1 provided). In this case it could make sense to delete the "Landing Pages" section altogether and instead use the category group not only for the navigation (first part of this nice answer) but also for the "Landing Pages" content.  
  > **username_1**: [Structures](http://buildwithcraft.com/docs/sections-and-entries) and [Entry Types](http://buildwithcraft.com/help/entry-type-templates) also work great for this as well, which you can also [build nav from](http://buildwithcraft.com/help/structure-nav).  
  
  ---
  
  