Issue
How can i get current category in magento2 ?
I want to get category name and category id in custom phtml file.
Solution
Try this code. this will definitely help you.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
echo $category->getId();
echo $category->getName();
?>
Answered By - Makwana Ketan Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.