I use the following code to get the categories in the left side of my store :
function categoryLoop($id, $is_sub = false){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categories = $objectManager->create('Magento\Catalog\Model\Category')->load($id);
if($categories->hasChildren()){
echo '<ul class="leftcat"' . (($is_sub) ? ' class="category_children category-'.$categories->getId().'"' : '') . '>';
$subcategories = explode(',', $categories->getChildren());
foreach ($subcategories as $category) {
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($category);
echo '<li><a href="'.$subcategory->getUrl().'">';
echo $subcategory->getName();
echo "</a></li>";
if($subcategory->hasChildren()){ categoryLoop($category, true); }
}
echo "</ul>";
}
}
categoryLoop(3);
How I can add a class "active" to the current / selected category?
Thank you