The variables parent_only tag allows to display only the “parent”category without sub categories.
Is there a way to achieve the opposite?
I want to display only the subcategories without the parent.
This works for me (not showing the main one)
{categories show="not 4"}
But the problem is I’m using URL titles.
And while I can get the ID with
{parent_id}
I don’t think you are able to use a parameter inside another such as:
{categories show="not {parent_id}"}
You’re correct that there is no “sub-categories_only” type parameter. You can accomplish with the query module using something like:
{exp:query sql="SELECT cat_name, cat_id, parent_id, group_id FROM exp_categories WHERE parent_id = '22' ORDER BY cat_order;"}
You can just list out all the IDs that you don’t want to show: ... WHERE parent_id = '22,45,66,22,...'...}
If this is something you see yourself needing often, feel free to open up a feature request for it on GitHub.
Thanks for the reply. Is there any way to highlight or show the active subcategories a channel is assigned besides using SQL queries?
It sounds strange that you cannot build a basic toc menu with a CMS software.
All I want is showing the user on which category they are while opening a specific channel URL.
Example, you create a documentation section, articles are obviously channels, and you use categories for each help section. Creating a menu that displays the nested categories is possible, but how would you show the active ones or have any visual cue in the menu to tell the user which category they are currently browsing?
Your own documentation is a clear example of this. Take this URL as an example:
https://docs.expressionengine.com/latest/fieldtypes/date.html
It shows you are on the Fieldtypes category viewing the Date section.
The Fieldtypes menu is now open, highlighted as active and so is the Data page.
I’m not exactly following how you are trying to show the active category with the snippet you showed in your opening post {categories show="not {parent_id}"}
.
It would seem to me that what you’re looking for is the {exp:channel:categories}
tag. With the {if active}
conditional. https://docs.expressionengine.com/latest/channels/categories.html#active . Which I think is what you were doing in your other post here: https://expressionengine.com/forums/topic/253052/active-category
If you don’t want to do this that way, then what people typically do is compare the segment variable they want to use to the category url_title. For example, if I have a list of categories where I want to set the current one active, and I know the category is always going to be segment_2, then I can do something like this:
{exp:channel:categories channel="news"}
<a href="http://{path=news/entry}class=active">{category_name}</a>
{/exp:channel:categories}
You may also need to use a combination of both methods if you want a parent category and sub-category both highlighted.
(btw. the docs aren’t build with EE. They are markdown files that are compiled so that anyone can easily contribute to them: https://github.com/packettide/ExpressionEngine-User-Guide )
I’m not exactly following how you are trying to show the active category with the snippet you showed in your opening post {categories show="not {parent_id}"}
.
It would seem to me that what you’re looking for is the {exp:channel:categories}
tag. With the {if active}
conditional. https://docs.expressionengine.com/latest/channels/categories.html#active . Which I think is what you were doing in your other post here: https://expressionengine.com/forums/topic/253052/active-category
If you don’t want to do this that way, then what people typically do is compare the segment variable they want to use to the category url_title. For example, if I have a list of categories where I want to set the current one active, and I know the category is always going to be segment_2, then I can do something like this:
{exp:channel:categories channel="news"}
<a href="http://{path=news/entry}class=active">{category_name}</a>
{/exp:channel:categories}
You may also need to use a combination of both methods if you want a parent category and sub-category both highlighted.
(btw. the docs aren’t build with EE. They are markdown files that are compiled so that anyone can easily contribute to them: https://github.com/packettide/ExpressionEngine-User-Guide )
Sorry for mixing up the topics. What I said about the active categories using EE docs as an example is actually what I was trying to achieve in the other forum post. Not here. I apologize for mixing it up. Maybe a moderator can move that reply to the proper topic.
On this specific forum post, what I wanted to achieve is just to show the subcategories under the current category you are browsing.
Let me explain and maybe this is far more simple than what I tried.
I create a template file that displays the existing category you are in, and it displays the articles under that category.
It shows the category you are in like this:
{exp:channel:category_heading channel="help"}
Main Category {category_name}</h2>
{/exp:channel:category_heading}
But under this text I want to create another text called:
Sub Categories
And here I want to output the subcategories from {category_name}
{category_name} is probably read by EE from the URL because in the URI I see: domain/template/category/website
Category is here my trigger name in EE, which means “Website” is the main category. You can load this way any category directly with the word instead of using the ID.
With the above code in the template file if we go to any category this way, the template automatically fills the category name you are currently viewing. But I also want to display the subcategories. Not all subcategories created, but only the ones under this main category we are currently viewing.
Does this make sense?
Your SQL query does work by the way. Is that the only way to get the sub categories currently? If yes, I can live with that, but just asking in case there is a native tag for this.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.