<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>

CC BY-SA 4.0
2024-09-06T13:07:52.903Z
Thank you for your help. Your solutions helped a lot) Noted all the answers. They are extremely useful )))
Dimi
CC BY-SA 4.0
2024-09-06T08:31:24.297Z
2024-09-06T08:31:24.297Z
James Smith
<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>

<entries><categories><craft4>
how can I display categories with their elements?
# 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 %}
    
        {% nav category in categories %}

                {% set prints = craft.entries().section('examples').categoryPrint(category).all() %}

                
                    - CATEGORY_{{ category.id }}
                    {% for print in prints %}
                        entry_{{print.id}}
                    {% endfor %}
                

                
                {% ifchildren %}
                    
                        {% children %}
                    
                {% endifchildren %}
                
        {% endnav %}
    
{% 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:

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 ](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 )))  

---

