Hello Friends,
Here is the code to get details of current category in magento 2.
Please add below code in list.phtml (or you want any page of catalog) and you will get the category details in magento 2.
You will get output like this
Here is the code to get details of current category in magento 2.
Please add below code in list.phtml (or you want any page of catalog) and you will get the category details in magento 2.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
var_dump($category->getData());
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
var_dump($category->getData());
You will get output like this
array(34) { ["store_id"]=> string(1) "1" ["entity_id"]=> string(1) "4" ["attribute_set_id"]=> string(1) "3" ["parent_id"]=> string(1) "2" ["created_at"]=> string(19) "2014-10-31 02:53:53" ["updated_at"]=> string(19) "2016-08-24 16:11:56" ["path"]=> string(5) "1/2/4" ["position"]=> string(1) "2" ["level"]=> string(1) "2" ["children_count"]=> string(1) "4" ["name"]=> string(9) "Furniture" ["image"]=> string(9) "mens1.png" ["meta_title"]=> NULL ["display_mode"]=> string(8) "PRODUCTS" ["custom_design"]=> string(0) "" ["page_layout"]=> string(0) "" ["default_sort_by"]=> NULL ["url_key"]=> string(9) "furniture" ["url_path"]=> string(14) "furniture.html" ["is_active"]=> string(1) "1" ["landing_page"]=> NULL ["is_anchor"]=> string(1) "1" ["include_in_menu"]=> string(1) "1" ["custom_use_parent_settings"]=> string(1) "1" ["custom_apply_to_products"]=> string(1) "1" ["description"]=> string(30) "
This is our custom text
" ["meta_keywords"]=> NULL ["meta_description"]=> NULL ["custom_layout_update"]=> string(0) "" ["available_sort_by"]=> NULL ["custom_design_from"]=> NULL ["custom_design_to"]=> NULL ["filter_price_range"]=> NULL ["path_ids"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "4" } }
if you want only get category name or id than you can use like This is our custom text
" ["meta_keywords"]=> NULL ["meta_description"]=> NULL ["custom_layout_update"]=> string(0) "" ["available_sort_by"]=> NULL ["custom_design_from"]=> NULL ["custom_design_to"]=> NULL ["filter_price_range"]=> NULL ["path_ids"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "4" } }
echo $category->getName(); echo $category->getId();
No comments :
Post a Comment