Product Category Name

To avoid unnecessary questions - I will immediately show the category page.
In the picture I tried to show the values.
How to display the value of the real category? , not a menu item!

By “real category” do you mean “Parent Category”?


Check this post or this post. I’m not sure if the suggestions work as I’m not able to test anything right now.

If not, then take a look at the Breadcrumbs or Layered Navigation code as that provide some hints to your solution.

No. Probably I need to explain in more detail.
The structure of the catalog: root - category - sub category - sub sub category - sub sub sub category which is hidden in the menu (there are up to 40 of them too long). The task is to get the name of the last category - what would be displayed in the upper categories (the product is also added to them) - I need to get the name of the final directory - which is hidden in the menu - but the product is shown.

Or maybe so better explained. The product has unique attributes - SKU and the name for example. They are taken from the product. The product can be in the highest categories waiting for the demonstration - how to display its final directory?

Is this what you’re getting at? If not, which one would apply in the example?

Default Category
├── Technology
├── Clothing
└── Home & Garden
    └── Homewares & accessories
        ├── Bedding
        ├── Lighting
        └── Home Furnishings
            └── Soft Furnishings
                └── Cushions
                    └── Clocks, Mirrors & Wall Art *(Get this category name)*
                        └── Item 123456 *(Product)*
Default Category
├── Technology
├── Clothing                                      
└── Home & Garden
    └── Homewares & accessories             ->    IN LEFT MENU
-------------------------------------------------------------------------------------------------------------------------
        ├── Bedding
        ├── Lighting
        └── Home Furnishings
            └── Soft Furnishings
                └── Cushions
                    └── Clocks, Mirrors & Wall Art *(Get this category name)*
                        └── Item 123456 *(Product)*

And in list: “sku” “product name” “Homewares & accessories” “Clocks, Mirrors & Wall Art” “In stock”

Using an adaptation of from the link I originally shared, I only see how you would grab the Child Category and its Parent Category. I don’t know how you’d grab anything else further down the chain.

<?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category'); //Get current category
    echo $category->getParentCategory()->getName(); // Print Parent Category
    echo "<br>"; //Line Break
    echo $category->getName(); //Print Current Category
?>

//Get current category
// Print Parent Category
But not sub…