Reputation:
I created this categories structure in my wordpress:
* Category1
* SubCategory1(of Category1)
* SubCategory2(of Category1)
* Category2
* SubCategory1(of Category2)
* Category3
I need to list on each category its subcategories.(without any post) So when I will access the Category one -> I should see only the subcategories. If the Main category does not have any subcategory -> I should see its posts.
My question1: What is the category page file name on wordpress? (I searched a lot but without any clear answer).
My question1: How to display for each main category(eg: Category1) only its children.
Upvotes: 1
Views: 15011
Reputation: 5231
Add on category.php page
<?php
if ( is_category() ) {
$current_cat = get_query_var('cat'); ?>
<ul>
<?php wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat); ?>
</ul>
<?php } ?>
http://codex.wordpress.org/Template_Tags/wp_list_categories
for taxonomy get sub category list taxonomy-producttax_category.php:
<?php $args = array(
'show_count' => 1,
'child_of' => get_queried_object()->term_id,
'taxonomy' => 'private_category', //define your taxeonomy
'title_li' =>'',
); ?>
<ul>
<?php wp_list_categories( $args ); ?>
</ul>
Upvotes: 2
Reputation: 1406
you can achieve that with this code:
<?php
if (is_category()) {
$this_category = get_category($cat);
}
?>
<?php
if($this_category->category_parent)
$this_category = wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent."&echo=0"); else $this_category = wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if ($this_category) { ?>
<ul>
<?php echo $this_category; ?>
</ul>
<?php } ?>
Upvotes: 0