I'm using WordPress.
Have multiple categories with its subcategories. In general page, I'm displaying all first level categories. Here is my code:
$args = array(
'type' => 'product-items',
'child_of' => 0,
'parent' => '',
'order' => 'DESC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'product-category',
'pad_counts' => false,
'depth' => 1,
'title_li' => ''
);
wp_list_categories($args);
Once you click and go inside a first level category, you need to see only its subcategories there. When I'm removing 'depth' => 1,
option, all children appear under their parent category but for page speed/load, in sub page I need to show all first-level categories, but only current category's children.
For example, I have below 3 categories:
- Category 1
- Category 2
- Category 3
Imagine I click on "Category 1". Now it is like this:
- Category 1
- 1st Sub Category of 1
- 2nd Sub Category of 1
- 3rd Sub Category of 1
- Category 2
- 1st Sub Category of 2
- 1st sub of 2nd category sub
- 2nd sub of 2nd category sub
- 3rd sub of 2nd category sub
- 2nd Sub Category of 2
- 3rd Sub Category of 2
- 1st Sub Category of 2
- Category 3
- 1st Sub Category of 3
- 2nd Sub Category of 3
- 3rd Sub Category of 3
But I need it to be like this in sub page:
- Category 1
- 1st Sub Category of 1
- 2nd Sub Category of 1
- 3rd Sub Category of 1
- Category 2
- Category 3
Not sure how to achieve this with wp_list_categories()
function. Any ideas please?