Wordpress 3 - parent / child category manipulation

In Wordpress it is possible to show subcategories of parent categories.

However, I only need to show the parent categories and then display the subcategories when the user clicks on the parent.

Let's say I have categories A and B. In A I have A1, A2 and A3. In B B1 and B2. Now I would like to show the categories on the interface ... something like:

Category A:
Category B:

      

When the user clicks on category A, I want the following:

Category A
- A1
- A2
- A3
Category B

      

When the user clicks on category B, I want the following:

Category A
Category B
- B1
- B2

      

Does anyone know if this is possible please? If yes, can you add pseudo code that can help me understand please?

+3


source to share


1 answer


I am assuming you are not asking how to get categories and subcategories, but you want to know how to render the html so that only parent categories and clicking parent subcategories are displayed. For this you need to use accordion menus. You can style them according to your needs. This way, all categories (parent and sub) will be displayed, but displayed the way you want.

Some examples of accordion menus, take a look at the html and you will get an idea of ​​how to display the html in your case.



example 1 example 2

+1


source







All Articles