0

This is the code I'm using for listing categories:

<?php 
     $this_category = get_queried_object();
     $args = array(
                    'orderby' => 'id',
                    'show_count' => '0',
                    'child_of' => $this_category->term_id,
                    'use_desc_for_title' => '0',
                    'taxonomy' => 'product_cat',
                    'hide_empty' => '0',
                    'child_of' => $this_category->term_id
      );     
      wp_list_categories($args); 
?> 

If I enter to some category it's listing subcategories, then if I enter to subcategories i want to stay subcategories listed like when im in previous category.

Is there a chance to do this?

  • I don't understand this question. – s_ha_dum Feb 2 '13 at 23:25
  • - category -- subcategory ---- sub-subcategory If I'm on "category" It's listing "subcategory", but when enter to "subcategory" I don't want to list "sub-subcategory" I want to list "subcategory" – Dime Feb 3 '13 at 0:03
0

If you know the depth that you want you can add a depth parameter to $args

 $args = array(
                'orderby' => 'id',
                'show_count' => '0',
                'child_of' => $this_category->term_id,
                'use_desc_for_title' => '0',
                'taxonomy' => 'product_cat',
                'hide_empty' => '0',
                'child_of' => $this_category->term_id,
                'depth' => 2
  );     
  wp_list_categories($args); 

Experiment with that number if it isn't what you want.

This does not get you "all but the last level" functionality though. It gets you some set number of categories deep. If you want "all but the last level", I think you will probably have to build a custom Walker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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