I'm trying to get a list of child categories within the toolbar.phtml but unsure how I can achieve this?

I have tried to use the category helper but this stops the category pages from loading and just shows empty white screen.

$categoryHelper = $this->helper('Magento\Catalog\Helper\Category');

foreach($categoryHelper->getChildrenCategories() as $category) {
    echo "Category Name Here?";

I will also need to be able to get a list of the parent category child categories if the current category doesn't have any children which would then show an active state on the current category.

Any help to be able to achieve this would be much appreciated.



Managed to get this to work :)

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentCategory = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
$childCategories = $currentCategory->getChildrenCategories();

foreach ($childCategories as $childCategory) {
    echo $childCategory->getUrl();
    echo $childCategory->getName();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.