Using Bootstrap Collapse with wp_list_categories (to make an accordion)
-
Hi everyone,
I’m trying to use Twitter Bootstrap to turn a list of parent categories and their children into an accordion (where the parent categories are the toggle links that expand and collapse the child categories).
I’m using
<?php wp_list_categories('title_li=&child_of=102&show_count=0'); ?>
to output:<ul> <li><a href="#">Parent</a> <ul class="children"> <li><a href="#">Child</a></li> <li><a href="#">Child</a></li> <li><a href="#">Child</a></li> </ul> </li> <li><a href="#">Parent</a> <ul class="children"> <li><a href="#">Child</a></li> <li><a href="#">Child</a></li> <li><a href="#">etc</a></li> </ul> </li> </ul>
In order to make this into an accordion, it needs to work like this:
<ul id="accordion"> <li><href="#collapseOne" data-toggle="collapse" data-parent="#accordion" data-target="#demo">Parent</a> <ul class="children collapse" id="collapseOne"> <li><a href="#">Child</a></li> <li><a href="#">Child</a></li> <li><a href="#">Child</a></li> </ul> </li> <li><href="#collapseTwo" data-toggle="collapse" data-target="#demo">Parent</a> <ul class="children collapse" id="collapseTwo"> <li><a href="#">Child</a></li> <li><a href="#">Child</a></li> <li><a href="#">etc</a></li> </ul> </li> </ul>
I’m starting to think this might not be possible with the wp_list_categories, due to changing the parent category links and using unique ids on each children ul.
Can anyone recommend a way around this (still using Bootstrap), using another wp function or approach?
Thank you in advance for your help.
Cheers,
Chris
- The topic ‘Using Bootstrap Collapse with wp_list_categories (to make an accordion)’ is closed to new replies.