1

I have a template that outputs a list of categories and any entries associated with them.

All entries are assigned to child categories and none to the parent categories (the parent categories exist only to aid organisation of the child categories).

When the list is output, the names of the parent categories are being shown (with no entries), then the child categories with their entries as expected.

It looks something like this

Cat1
    Cat 1A
        (entries)
    Cat 1B
        (entries)
    Cat 1C
        (entries)
Cat2
    Cat 2A
        (entries)
    Cat 2B
        (entries)
Cat3
    Cat 3A
        (entries)
    Cat 3B
        (entries)

How can I not show the parent categories but keep the child categories showing?

i.e. the output will look like this...

    Cat 1A
        (entries)
    Cat 1B
        (entries)
    Cat 1C
        (entries)
    Cat 2A
        (entries)
    Cat 2B
        (entries)
    Cat 3A
        (entries)
    Cat 3B
        (entries)

Is my only option to remove the parent categories completely?

Here's my current template code

{exp:channel:categories channel="attachments" category_group="2" parent_only="no" style="linear" show_empty="no"}

    <h3>{category_name}</h3>
    {exp:channel:entries channel="pages" entry_id="112" }
        {exp:playa:children field="attachment" category="{category_id}" disable="members"}
                <ul>        

                    <li>
                        <a href="{attachment-file}">{attachment-file-text}</a>
                    </li>

                </ul>
                {/exp:playa:children}
    {/exp:channel:entries}

{/exp:channel:categories}
2

Add:

{if {parent_id} != 0}
    ...
{/if}

(This only works for hiding root parents, not 3 tier structures)

{exp:channel:categories channel="attachments" category_group="2" parent_only="no" style="linear" show_empty="no"}

{if "{parent_id}" != 0}
    <h3>{category_name}</h3>
    {exp:channel:entries channel="pages" entry_id="112" }
        {exp:playa:children field="attachment" category="{category_id}" disable="members"}
                <ul>        

                    <li>
                        <a href="{attachment-file}">{attachment-file-text}</a>
                    </li>

                </ul>
                {/exp:playa:children}
    {/exp:channel:entries}
{/if}
{/exp:channel:categories}

But be very careful of performance here - might be worth flipping the categories and entries tags, as channel:entries has more overhead than channel:categories, so a single entries tag and looping of the categories tag may improve performance.

| improve this answer | |
  • Perfect. I'm aware of the potential performance hit but we are talking about maybe a dozen categories and only about 30 entries. The number won't ever grow much over that so for the moment this works well enough. – foamcow Oct 7 '13 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.