I'm having trouble wrapping my head around how to create a dynamic menu with GWcode categories in ExpressionEngine. I would like the menu to go a certain depth only for current {segment_2} (parent) category and the rest of the parent categories to just stay a depth of 1.
For instance, if the url was: domain.com/products/medical-tables-cabinets/eta-classic-series/ it would output this:
<ul class="nav-menu">
<li><a href="#">Power Tables</a></li>
<li class="active submenu"><a href="#">Medical Tables & Cabinets</a>
<ul class="nav-submenu">
<li><a href="#">ETA Alpha Series</a></li>
<li class="active submenu"><a href="#">ETA Classic Series</a>
<ul class="nav-submenu">
<li><a href="#">Entry A</a></li>
<li><a href="#">Entry B</a></li>
<li><a href="#">Entry C</a></li>
</ul>
</li>
<li><a href="#">Style Line Cabinet Models</a></li>
<li><a href="#">Echo Image Series</a></li>
<li><a href="#">Bariatric Series</a></li>
<li><a href="#">Family Practice</a></li>
<li><a href="#">Treatment & Bedside Cabinets</a></li>
<li><a href="#">Managed Care Quick Cabinets</a></li>
<li><a href="#">Recovery Couches</a></li>
</ul>
</li>
<li><a href="#">Pediatric Equipment</a></li>
<li><a href="#">Medical Seating</a></li>
<li><a href="#">Blood Drawing Chairs</a></li>
<li><a href="#">Tubular Steel & Accessories</a></li>
<li><a href="#">Physical Therapy Equipment</a></li>
<li><a href="#">Kangoo by Clinton</a></li>
<li><a href="#">Training Room Furnishings</a></li>
<li><a href="#">Index by Model #</a></li>
<li><a href="#">Clinton-Eco Tables</a></li>
</ul>
I got it working, but I still need to go a little deeper. Here is the basic concept:
{exp:gwcode_categories
channel="products"
style="linear"
}
{if depth1_start AND segment_2 != cat_url_title}
<li><a href="/products/{complete_path}">{cat_name}</a></li>
{/if}
{if depth1_start AND segment_2 == cat_url_title}
<li class="active submenu"><a href="/products/{complete_path}">{cat_name}</a>
<ul class="nav-submenu">
{/if}
{if depth == 2 AND segment_2 == parent_url_title}
<li{if segment_3 == cat_url_title} class="active"{/if}><a href="/products/{complete_path}">{cat_name}</a></li>
{/if}
{if depth1_end AND segment_2 == parent_url_title}
</ul>
</li>
{/if}
{/exp:gwcode_categories}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With