1

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.

1 Answer 1

1

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

2
  • please take a look on my updated question, maybe Youl get a better idea of what exactly Im trying to do. Thanks @wilhelser
    – NoBine
    Nov 27, 2013 at 2:28
  • @NoBine Can you please post the solution here? I am struggling with the same thing. Thanks.
    – souravb
    Oct 15, 2017 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.