Add product category tree sidebar to archive and single product pages (v0.1.7)
All checks were successful
Create Release Package / PHP Lint (push) Successful in 1m4s
Create Release Package / PHPUnit Tests (push) Successful in 50s
Create Release Package / Build Release (push) Successful in 58s

Hierarchical category navigation with collapsible sub-levels up to 3 levels
deep, using Bootstrap 5 list-group and collapse components. Sidebar renders
on both archive/shop and single product pages with responsive offcanvas on
mobile. Active category highlighting and ancestor auto-expand for intuitive
navigation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 15:19:53 +02:00
parent 5e4af247fa
commit 9860a184cd
9 changed files with 332 additions and 8 deletions

View File

@@ -0,0 +1,46 @@
{#
# Single Category Tree Node (recursive)
#
# Renders one category with optional collapsible children.
# Included recursively by category-tree.html.twig.
#
# Expected context:
# node - Category node from wc_bootstrap_get_category_tree()
# level - Current nesting depth (1-3)
#
# @package WcBootstrap
# @since 0.1.7
#}
<li class="list-group-item px-0 py-1 border-0">
<div class="d-flex align-items-center">
<a href="{{ node.url }}"
class="category-tree-link d-block text-decoration-none py-1 px-2 rounded flex-grow-1{% if node.is_active %} active fw-semibold{% endif %}"
{% if node.is_active %}aria-current="page"{% endif %}>
<span class="ps-{{ (level - 1) * 2 }}">
{{ node.name }}
</span>
<span class="badge bg-body-secondary text-body-secondary rounded-pill ms-1 small">{{ node.count }}</span>
</a>
{% if node.children is not empty %}
<button class="btn btn-sm btn-link text-body-secondary p-0 ms-1 category-tree-toggle"
type="button"
data-bs-toggle="collapse"
data-bs-target="#cat-{{ node.term_id }}"
aria-expanded="{{ node.is_active or node.is_ancestor ? 'true' : 'false' }}"
aria-controls="cat-{{ node.term_id }}"
aria-label="{{ __('Toggle subcategories', 'wc-bootstrap') }}">
<i class="bi bi-chevron-down small" aria-hidden="true"></i>
</button>
{% endif %}
</div>
{% if node.children is not empty %}
<ul class="list-group list-group-flush collapse{{ node.is_active or node.is_ancestor ? ' show' : '' }}"
id="cat-{{ node.term_id }}">
{% for child in node.children %}
{% include 'global/category-tree-node.html.twig' with { node: child, level: level + 1 } only %}
{% endfor %}
</ul>
{% endif %}
</li>