You've already forked wc-bootstrap
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>
35 lines
1.2 KiB
Twig
35 lines
1.2 KiB
Twig
{#
|
|
# Product Category Tree (Bootstrap 5)
|
|
#
|
|
# Renders a hierarchical product category navigation with collapsible
|
|
# sub-levels, up to 3 levels deep. Uses Bootstrap 5 list-group and
|
|
# collapse components for responsive tree navigation.
|
|
#
|
|
# Expected context:
|
|
# categories - Hierarchical array from wc_bootstrap_get_category_tree()
|
|
# shop_url - URL to the main shop page
|
|
#
|
|
# @package WcBootstrap
|
|
# @since 0.1.7
|
|
#}
|
|
|
|
{% if categories is not empty %}
|
|
<nav aria-label="{{ __('Product categories', 'wc-bootstrap') }}">
|
|
<h3 class="sidebar-heading h6 text-uppercase fw-semibold">
|
|
{{ __('Categories', 'wc-bootstrap') }}
|
|
</h3>
|
|
|
|
<ul class="list-group list-group-flush category-tree">
|
|
<li class="list-group-item px-0 py-1">
|
|
<a href="{{ shop_url }}"
|
|
class="category-tree-link d-block text-decoration-none py-1 px-2 rounded{% if current_cat == 0 %} active fw-semibold{% endif %}">
|
|
{{ __('All products', 'wc-bootstrap') }}
|
|
</a>
|
|
</li>
|
|
{% for cat in categories %}
|
|
{% include 'global/category-tree-node.html.twig' with { node: cat, level: 1 } only %}
|
|
{% endfor %}
|
|
</ul>
|
|
</nav>
|
|
{% endif %}
|