Forum

Thread tagged as: Question

create category template for nested menu

Is it possible to create a template to output nested categories, for example to create a collapsable menu. e.g.

<ul>
  <li><a>shirts</a>
    <ul>
      <li><a>long sleeve</a></li>
      <li><a>short sleeve</a></li>
    </ul>
  </li>
  <li><a>trousers</a>
    <ul>
      <li><a>jeans</a></li>
      <li><a>chinos</a></li>
    </ul>
  </li>
</ul>
Mark Smith

Mark Smith 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The category templates aren't recursive like the navigation templates (although we should add an option for that), so I'm not sure there's a great way to output a nested list just now.

OK Drew thanks for response.

This is how I'm considering getting around that incase it's useful to anyone.

$cats = perch_categories(array('category' => 'Products', 'skip-template' => true));
$cats_menu = array_filter($cats, function($var) {
    return $var['catDepth']===1;
});
array_walk($cats_menu, function(&$value) use($cats) {
    $value['children'] = array_filter($cats, function($var) use($value) {
        return $var['catParentID']===$value['catID'];
    });
});