Wordpress Display sub-categories of category
How to display sub categories of any Category ??? by coding
Wordpress has all inbuilt functions whose can do this task in seconds but many wordpress holder has problem that they really dont know much about wordpress functions. so i have decided to start adding posts for simple function in our blogs too.
I have noticed many times small and simple thing wastes many time.
Display Sub categories of category
use this function
<?php wp_list_categories(’show_count=1&child_of=154&title_li=<h2>Category name</h2>’); ?>
154 = Category Id ( You can view it from wp-admin, while try to edit any category, id will display in browser address bar)
Category name: you can add your category name or what else you want to display
2 more thing to know
suppose you have listing of category already on your page, and you want to display particular category listing seperately. for display particular category you can use above example.
But if you added 2nd category list seperately so you 1st category still showing all category. insort duplicay of 2nd category list.
How to prevent that ?
use this function
this exclude query can not allow your 1st list to display your particular category and its subcategory on your 1st list
<?php wp_list_categories(’show_count=1&exclude=154&title_li=<h2>Categories</h2>’); ?>
like above one.










June 27th, 2009 at 8:45 pm
Hi,
This is great!
I’ve changed my permalink settings to use a descriptive name rather than an ID. Is there a way for me to do the same thing but not with an ID? I’m new to all this.
June 29th, 2009 at 8:58 am
you have to use Id to display subcategory. if you want you can use this function to convert your category name into Id.
< ?php // get category name's ID then insert into wp_list_categories ?>
< ?php $category = get_category_by_slug('Archive');
$catid = $category->term_id; ?>
< ?php wp_list_categories('exclude='.$catid); ?>
July 12th, 2009 at 4:02 am
Более 3х лет постоянно обеспокоен этой проблемой и думаю ваши доводы особо легкомысленными
July 14th, 2009 at 8:01 pm
Thanks San
January 31st, 2010 at 10:30 am
I am trying to use a custom template on one of my categories-
webcyonix.com/digi/category/magazine/archivepast-issue
I want to display its sub-categories which are actually month-names. For this I have created “category-47.php” which is its template. But when I paste ur code, it shows a php error. Can you please guide me how can I fix this, or display all its sub-categories on the new template page. Thanks in advance mate