Reputation: 11
Lets say I have a list of categories
I`m trying to hide the top categories (P1,P2...), but stil keeping the hierarchical structure of my list.
P1
-Ch1P1
--Ch1.1P1
--Ch2.1P1
--Ch3.1P1
-Ch2P1
--Ch1.2P1
--Ch2.2P1
-Ch3P1
--Ch1.3P1
P2
-Ch1P2
--Ch1.1P2
--Ch1.2P2
-Ch2P2
--Ch1.2P2
-Ch3P2
P3
-Ch1P3
--Ch1.1P3
--Ch2.1P3
-Ch2P3
--Ch1.2P3
.
.
.
How to list hierarchical without the top-level Parent (without P1, P2, P3) ???
UPDATE:
here is my code:
<?php
// Get Current post ID (BRAND SLUG)
$BrandSlug = get_queried_object()->slug;
$BrandName = get_queried_object()->name;
// List of Categories prom This BRAND
$args = array('post_type' => 'product', 'brands'=>$BrandSlug ,'post_status' => 'publish', 'posts_per_page'=>'1000');
$products = get_posts( $args );
// Defining necessary arrays
$ProductCategories = array();
$ProductCategoryParent = array();
foreach( $products as $product ) : setup_postdata($post);
$Categories = get_the_terms( $product->ID, 'product-category' );
foreach ( $Categories as $Category ) {
//if( $Category->parent > 0 ){
$ProductCategories[] = $Category->term_id;
//}
}
endforeach;
$cargs = array(
'show_option_all' => false,
//'orderby' => 'slug',
//'order' => 'DESC',
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
//'child_of' => 201,
//'feed' => '',
//'feed_type' => '',
//'feed_image' => '',
//'exclude' => '197',
//'exclude_tree' => '197',
'include' => $include,
'hierarchical' => true,
'title_li' => 'Current Brand (<b>'.$BrandName.'</b>)',
'show_option_none' => 'No Categories',
'number' => null,
//'echo' => $visible,
'depth' => 0,
//'current_category' => $myCat,
//'pad_counts' => 0,
'taxonomy' => 'product-category',
'walker' => null
);
echo '<ul id="brand_categories">';
wp_list_categories($cargs);
echo '</ul>';
?>
The idea is that I schould see in the categories listed ony categories that have products from current brand.
Upvotes: 1
Views: 2061
Reputation: 11
You want to use:
&child_of=Category_id
So if your category id was 9 and you wanted to display an unordered list of all that category's children, you could do:
<ul>
<?php wp_list_categories('orderby=id&show_count=1&use_desc_for_title=0&child_of=9'); ?>
</ul>
From http://codex.wordpress.org/Template_Tags/wp_list_categories
Upvotes: 1