Answers.Body: <p>I believe you're looking for the Maintain hierarchy&quot; checkbox on the category selector field. If you <em>uncheck</em> it, it'll ensure that relationships are only made with the single category you select and not its ancestors.</p>
  <p><a href="https://i.sstatic.net/G4ilVhQE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/G4ilVhQE.png" alt="A screenshot of the &quot;Maintain Category Hierarchy&quot; checkbox" /></a></p>
  <hr />
  <p>Unrelated, but if you get a chance, please could you also accept my answers to three of your other recent questions if they helped you:</p>
  <p><a href="https://craftcms.stackexchange.com/questions/41914/how-can-i-display-a-list-of-all-the-years-for-which-there-are-entries/41922#41922">How can I display a list of all the years for which there are entries?</a></p>
  <p><a href="https://craftcms.stackexchange.com/questions/41921/how-to-filter-elements-by-multiselect-field-via-relatedto/41923#41923">How to filter elements by multiselect field via relatedTo</a></p>
  <p><a href="https://craftcms.stackexchange.com/questions/41589/how-do-i-authorize-register-visitors-on-the-site">How do I authorize/register visitors on the site?</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-06T13:07:52.903Z
Answers.Text: Thank you for your help. Your solutions helped a lot) Noted all the answers. They are extremely useful )))
Answers.UserDisplayName: Dimi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-06T08:31:24.297Z
Answers.LastActivityDate: 2024-09-06T08:31:24.297Z
Answers.UserDisplayName: James Smith
Body: <p>I can't get a full-fledged tree of categories with their elements. That's how I'm trying to do it.:</p>
  <pre><code>{% if categories %}
      &lt;div class=&quot;categories print&quot;&gt;
          {% nav category in categories %}
  
                  {% set prints = craft.entries().section('examples').categoryPrint(category).all() %}
  
                  &lt;div&gt;
                      &lt;strong&gt;- CATEGORY_{{ category.id }}&lt;/strong&gt;
                      {% for print in prints %}
                          &lt;div style=&quot;padding: 0 0 0 25px&quot;&gt;entry_{{print.id}}&lt;/div&gt;
                      {% endfor %}
                  &lt;/div&gt;
  
                  
                  {% ifchildren %}
                      &lt;div style=&quot;padding: 0 0 0 25px&quot; class=&quot;sub-categories&quot;&gt;
                          {% children %}
                      &lt;/div&gt;
                  {% endifchildren %}
                  
          {% endnav %}
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  <p>And my code works, but there is an inaccuracy that I do not know how to fix. The fact is that in the parent categories, the elements that belong to the child categories are displayed:
  <a href="https://i.sstatic.net/CbpFjLBr.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CbpFjLBr.png" alt="enter image description here" /></a></p>
  <p>Please help me, how to solve this?</p>
  
Tags: <entries><categories><craft4>
Title: how can I display categories with their elements?
ThreadText: # how can I display categories with their elements?
  
  (Asked by: username_0 on 2024-09-05)
  
  I can't get a full-fledged tree of categories with their elements. That's how I'm trying to do it.:
  
  ```
  {% if categories %}
      <div class="categories print">
          {% nav category in categories %}
  
                  {% set prints = craft.entries().section('examples').categoryPrint(category).all() %}
  
                  <div>
                      <strong>- CATEGORY_{{ category.id }}</strong>
                      {% for print in prints %}
                          <div style="padding: 0 0 0 25px">entry_{{print.id}}</div>
                      {% endfor %}
                  </div>
  
                  
                  {% ifchildren %}
                      <div style="padding: 0 0 0 25px" class="sub-categories">
                          {% children %}
                      </div>
                  {% endifchildren %}
                  
          {% endnav %}
      </div>
  {% endif %}
  
  ```
  
  And my code works, but there is an inaccuracy that I do not know how to fix. The fact is that in the parent categories, the elements that belong to the child categories are displayed:
  [![enter image description here](https://i.sstatic.net/CbpFjLBr.png)](https://i.sstatic.net/CbpFjLBr.png)
  
  Please help me, how to solve this?
  
  **Tags:** entries, categories, craft4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-09-06. Score: 1 | Accepted answer
  
  I believe you're looking for the Maintain hierarchy" checkbox on the category selector field. If you *uncheck* it, it'll ensure that relationships are only made with the single category you select and not its ancestors.
  
  [![A screenshot of the "Maintain Category Hierarchy" checkbox](https://i.sstatic.net/G4ilVhQE.png)](https://i.sstatic.net/G4ilVhQE.png)
  
  ---
  
  Unrelated, but if you get a chance, please could you also accept my answers to three of your other recent questions if they helped you:
  
  [How can I display a list of all the years for which there are entries?](https://craftcms.stackexchange.com/questions/41914/how-can-i-display-a-list-of-all-the-years-for-which-there-are-entries/41922#41922)
  
  [How to filter elements by multiselect field via relatedTo](https://craftcms.stackexchange.com/questions/41921/how-to-filter-elements-by-multiselect-field-via-relatedto/41923#41923)
  
  [How do I authorize/register visitors on the site?](https://craftcms.stackexchange.com/questions/41589/how-do-i-authorize-register-visitors-on-the-site)
  
  > **Comments:**
  > **username_0**: Thank you for your help. Your solutions helped a lot) Noted all the answers. They are extremely useful )))  
  
  ---
  
  