Topic List Custom Template

Permalink
Need a little help with my topic list custom template. I'm attempting to structure the Search Mode as an accordion rather than a bulleted list. I have most of it worked out, but I can't fix one problem.

I have a topic list akin to the following:

Category 1
Point 1
Point 2
Point 3
Category 2
Point 1
Point 2
Point 3

I have added 2 counters. One to tell me when I am at the beginning/end of the point lists and one to tell me which category I am in. These are built into the foreach statement (see code below). However, instead of running through the topic tree sequentially it seems to be doing the following:

Category 1 ( href = #Link1)
Point 1 ( id = Link1)
Point 2 ( id = Link1)
Point 3 ( id = Link1)
Category 2 (href = #Link2)
Point 1 ( id = Link1)
Point 2 ( id = Link1)
Point 3 ( id = Link1)

Why? I don't know. Any help would be appreciated. The code is below. Here is my testing page:http://pinecrestchurch.com/ministries-head/testing...

Edit::
I am basing my accordion mark up on the following:https://codepen.io/rugor/pen/hwyzn/...


if ($mode == 'S' && is_object($tree)):
        $node = $tree->getRootTreeNodeObject();
        $node->populateChildren();
        if (is_object($node)) {
            $walk = function($node) use (&$walk, &$view, $selectedTopicID) {
                $i = 1;
             $a = 1;
                foreach($node->getChildNodes() as $topic) {
                    if ($topic instanceof \Concrete\Core\Tree\Node\Type\TopicCategory) { ?>
                  <?php if ($a > 1) { ?>
                     </ul></li></ul>
                  <?php }; ?>
                        <ul class="nav nav-stacked" id="accordion<?php echo $a; ?>"><li class="panel"><a data-toggle="collapse" data-parent="#accordion<?php echo $a; ?>" href="#Link<?php echo $a; ?>"><?php echo $topic->getTreeNodeDisplayName()?></a>
                    <?php } else { 
                  if ($i == 1) {?>

 
siton replied on at Permalink Reply
siton
Its hard to know without testing this code.

In the past i made 4-5 topic list templates (look at the array classes in codepen).
In accordion most of the time the parent is "#" but beside this you dont need to change the code for the HREF. So you need to find "when li is parent or ul" = answer "yes" so: href=#" & some data-js and thats it.

See "C" topic (dont click on the rest ).
http://codepen.io/siton/pen/MejbWB...

Mabye other user will test this. I read this from mobile.

Mabye add your accordion plugin markup link (JS)
Freckles replied on at Permalink Reply
I am using the bootstrap framework. From what I've seen in bootstrap, the parent href is linked to the sublist id. Meaning each section needs its own unique id. I placed the link to the markup I'm basing my code above. It is also here:https://codepen.io/rugor/pen/hwyzn/...
Freckles replied on at Permalink Best Answer Reply
Realized my error. The array is not ordered sequentially, so when I run through the foreach my counter is being reset each time. The fact that it worked for the first dropdown was coincidence.