Is it possible to determine if there are any or how many subcategories are there in a category?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
June 13, 2011 7:40am
Subscribe [3]#1 / Jun 13, 2011 7:40am
Is it possible to determine if there are any or how many subcategories are there in a category?
#2 / Jun 13, 2011 9:43am
Hi
As far as I’m aware you can have unlimited sub categories.
#3 / Jun 13, 2011 10:07am
this is not what I meant - I need a code displaying how many subcategoies are there in a given category or at least if there are any subcategories in a category - is it possible?
#4 / Jun 13, 2011 10:20am
Hi
Sorry. This is what you need to display all categories being used by Entries within a specific Channel e.g. News
{exp:channel:categories channel="News" show_empty="yes" category_group="2"}
{count}
{/exp:channel:categories}The show_empty parameter will force the total count to include categories which do not have an Entry assigned to them.
The category_group parameter restricts the count to a single category group if needed.
Hopefully that helps.
#5 / Jun 13, 2011 12:25pm
thank you Matt but still it’s not what I need. Lets say I have such categories:
- Category 1
* entry 1
* entry 2
* entry 3
- Category 2
+ subcategory 1
* entry 4
* entry 5
* entry 6
+ subcategory 2
* entry 7
* entry 8
+ subcategory 3
* entry 9
- Category 3
* entry 10
* entry 11
* entry 12
- Category 4
+ subcategory 4
* entry 13
I want to display everything on one page, with different styling for categories and subcategories. As you see some categories have just entries, other have subcategories which also have entries. How can know if a category have subcategories or just entries?
#6 / Jun 14, 2011 7:57am
Hi, PipSpratt.
I haven’t used this third party add-on, but it might be a starting point for you: Categories
Found by searching Devot-ee.com for categories.
#7 / Jun 14, 2011 8:32am
Hi PipSpratt
How can know if a category have subcategories or just entries?
You can assign an entry to a Category OR Sub Category OR BOTH. So in your example a single Entry can be assigned to Category 2 and Sub Category 3.
By nature and Entry within a sub-category is part of the parent category anyway.
To answer your question above. A category can contain a Sub Category and at the same time have Entries assigned to it (without being assigned to any sub categories it may contain)
e.g.
Entry: Matt
Category: Staff, Designer (sub cat of Staff)
Entry: “Justin”
Category: Staff
PS: check out this page of the user guide for more to do with categories…
#8 / Jun 14, 2011 8:40am
I tried to assign an entry to subcategory and not to category but whenever I unchecked a category in publish page, it was always checked again when I wanted to edit this entry again. How can I assign an entry to just subcategory?
#9 / Jun 14, 2011 9:40am
Hi, PipSpratt.
Under Global Category Preferences, set the value of Auto-Assign Category Parents to No.
See attached screen shot.
#10 / Jun 14, 2011 10:18am
thank you Sue - that solved my problem 😊
#11 / Jun 14, 2011 10:28am
PipSpratt - so are we OK to close this particular thread, then?
#12 / Jun 14, 2011 10:58am
yes we are 😊
#13 / Jun 14, 2011 11:11am
Glad to hear it. 😊 If anything else comes up, please do let us know in a new thread..