Sidebar menu that doesn't change after page selection

This has been plaguing me for a while, and while I’m sure it’s something simple, I’m stuck. I’m trying to create a sidebar menu that lists only what is inside a specific folder. This code:
—html

    {% for p in taxonomy.findTaxonomy({'category':page.taxonomy.category}) if p != page %}
  • {% if p.children|length > 0 %}

    {{ p.title }}

    {% else %} {% if p.parent.title == page.taxonomy.category[1] %} {{ p.title }} {% endif %} {% endif %}
  • {% endfor %}
``` Mostly does the trick. However, if I click on one of the links it creates, the menu changes and the menu rebuilds listing all of the folders at the top of the structure. So if my menu starts like this: --- Layout (folder) Header (page) Grid Lists Elapsed Time Timestamp Avatar HR Lists Ordered Lists Unordered Lists Navigation Primary Navigation Breadcrumbs Pagination Tabs User Input Typeahead Select Menu Text Fields Checkbox Radio Button Search Actions Link States Default Buttons ``` It ends up with this at the top: ``` Patterns Layout Navigation Data-display Data-controls Formatting User Input Actions Layout Header Grid Lists Elapsed Time Timestamp Avatar HR Lists Ordered Lists Unordered Lists ---

There’s probably a better way to do this, but this is what I have that creates the menu how I want it based on a series of directories.

{% macro loop(page) %}
  {% for p in page.children %}
    {% if p.visible %}
      {% set current_page = (p.active or p.activeChild) ? 'active' : '' %}

      {% if p.children.count > 0 %}
        <li>
          <p>{{ p.title }}</p>
          <ul class="sub-topics">
            {{ _self.loop(p) }}
          </ul>
        </li>
      {% else %}
        <li class="dd-item" data-nav-id="{{ p.route }}">
          <a href="{{ p.url }}" title="{{ p.title }}">{{ p.title }}</a><i class="{{ page.status }}"></i>
        </li>
      {% endif %}
    {% endif %}
  {% endfor %} 
{% endmacro %}

<ul class="topics">
  {% for p in taxonomy.findTaxonomy({'category':page.taxonomy.category}) %}
    {% if p.title|lower != 'patterns' and p.title|lower != 'styling' and p.title|lower != 'anatomy' %}
      {% if p.children.count > 0 %}
        <li>
          <p>{{ p.title }}</p>
          <ul class="sub-topics">
            {{ _self.loop(p) }}
          </ul>
        </li>
      {% else %}
        {{ _self.loop(p) }}
      {% endif %}
    {% endif %}
  {% endfor %}
</ul>

The menu was changing as I navigated into the directory and the route changed.