Hi,
I’ve been having a tough time getting the categories tag to behave the way I need it to. Basically, I want to show an intro in my template with the current category I am in, regardless of whether that category has a parent or not.
After the category I show the entries for that category.
However, it seems as though the parent id is obligatory in the “show=id” parameter, so I must show the parent as well?
Am I missing something?
It seems like it should be a pretty straightforward to just grab a child category by its ID. The only way I’ve been able to achieve this is by doing something like the following:
{exp:query sql="SELECT parent_id,cat_id FROM exp_categories WHERE cat_url_title = '{segment_4}'"}
{!-- if the category has a parent, show the parent and the child --}
{if parent_id != "0"}
{exp:channel:categories channel="{channel_name}" show="{parent_id}|{cat_id}" style="linear"}
{category_name_{lang_code}}
{/exp:channel:categories}
{!-- otherwise we are on a regular top level category --}
{if:else}
{exp:channel:categories channel="{channel_name}" show="{cat_id}" style="linear"}
{category_name_{lang_code}}
{/exp:channel:categories}
{/if}
{/exp:query}
This kind of works, I get back the parent and the child. But it would be nice to just be able to show a child category without having to also show its parent.