Display Sub Categories under category archives
-
Would it be possible to display sub-categories in a sidebar in category archive pages – say if someone were to open a catgory called “Journal” it would display sub-categories of journal in the sidebar?
-
Still looking for help – tried a number of variants and my brain is fit to explode
What about the Documentation?
http://codex.ww.wp.xz.cn/Template_Tags/wp_list_catsHave read the documentation [that was my first port of call after all] but I found nothing that would help me get the template to only show a list of sub-categories under the category current being viewed.
Aah, now I clearly understand what you want. You want this:
Category 1 (we are reading category 1)
–Sub-cat 1-1
–Sub-cat 1-2
–Sub-cat 1-3
Category 2
Category 3Answer: not possible.
Either you get all categories + their sub-categories displaid at the same time (with the wp_list_cats tag), or you can display the sub categories below the category listing by puting some codes, e.g.:
Category 1
Category 2
Category 3
——
Sub-cat 1-1
Sub-cat 1-2
Sub-cat 1-3I tried to turn around, and I only came up with the above solution. Not very nice.
I understand why WordPress can’t do it (for coding reasons and because a post can have several categories). So, it is not a bug, it’s a feature !I’m not sure that is what I want.
What I want is something that would show only the sub-categories on a category archive page in the sidebar
Say for example I have a category called “Journal” with six sub-categories – 2001, 2002, 2003, 2004, 2005, 2006.
When I am viewing sub-category journal I wanted the six sub-categories to show in the sidebar in list form.
Not sure preventing something as simple as that counts as a feature.
Its a shame it is not possible to do something like this
<?php wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title=0&child_of=THIS ONE’); ?>
The this one being something that would call the current category being viewed and only display sub-categories
<?php wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title
=0&child_of=8′); ?><?php wp_list_cats(‘sort_column=id&optioncount=
0&use_desc_for_title=0&child_of=8′); ?>What I am trying to say it is a shame perhaps there isn’t a way to persuade wordpress to place the cat ID in automatically… rather than having to enter it manually to only list children of a certain category
Tried this
<?php
wp_list_cats(‘list=1&use_desc_for_title=0&child_of=’ . $this_category->category_parent); ?>But I just couldn’t seem to get it to work. Came up no categories.
As I wrote in my previous message, I came up with a solution, and by reading you, it seems this is what you want. Please, find below the code I use to display sub-categories. It will display them in both Category pages, and in the post where it belongs. However, you have to give the category parent ID where the sub-categories belong in order to display them:
<?php /* Display sub-categories, you have to add manually the parent catgeory ID concerned */ $this_category = get_category($cat); if (($this_category->cat_ID == 1) or ($this_category->cat_ID == 4) or ($this_category->cat_ID == 5)) { ?>
<h4><?php echo $this_category->cat_name; ?>Sub-Categories:</h4>
<ul class="sub-categories">
<?php wp_list_cats('sort_column=ID&sort_order=asc&list=1&optioncount=0&hide_empty=0&use_desc_for_title=1&children=0&child_of='.$cat.'&Categories=0&hierarchical=1'); ?>
</ul><?php } elseif (($this_category->category_parent == 1) or ($this_category->category_parent == 4) or ($this_category->category_parent == 5)) { ?>
<h4><?php echo(get_category_parents($this_category->category_parent, FALSE, '', FALSE)); ?>Sub-Categories:</h4>
<ul class="sub-categories">
<?php wp_list_cats('sort_column=ID&sort_order=asc&list=1&optioncount=0&hide_empty=0&use_desc_for_title=1&children=0&child_of='.$this_category->category_parent.'&Categories=0&hierarchical=1'); ?>
</ul>
<?php } /* end of Display sub-categories */ ?>Note: it must be inside The Loop. It put this in my sidebar, so, your sidebar must be within The Loop.
Thank you so much!!
Hi, I’m using this “Fold Category List” plugin to achieve similar results.
http://www.webspaceworks.com/resources/wordpress/31/
The topic ‘Display Sub Categories under category archives’ is closed to new replies.