I have a php code that display all categories of my store, the only problem with this code is give me this structure: ul > li > ul > li. I want to be able to change in css for example the Parent Category to have the color red and Child Category to have the color blue.
I try to use something like:
.sidebar.sidebar-additional ul li:first-child {color: red;}
but is not okay, both texts Parent Category and Child Category have the same red color.
What I can do be able to select both texts separately?
function categoryLoop($id){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categories = $objectManager->create('Magento\Catalog\Model\Category')->load($id);
if($categories->hasChildren()){
echo '<ul>';
$subcategories = explode(',', $categories->getChildren());
foreach ($subcategories as $category) {
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($category);
echo '<li>';
echo $subcategory->getName();
echo "</li>";
if($subcategory->hasChildren()){ categoryLoop($category); }
}
echo "</ul>";
}
}
The html output is:
<ul>
<li>Parent Category</li>
<ul>
<li>Child Category 1</li>
<li>Child Category 2</li>
<li>Child Category 3</li>
</ul>
</li>
</ul>
Thank you