I have a category landing phtml, I want to add a this main category name there.
This page is main category page, under this main category page, it has few subcategory.
I would like to get the MAIN category name in this landing page. But I cannot retrieve it.
<?php
$viewModel = $block->getViewModel();
?>
<div class="category-landing-grid">
<?php foreach ($viewModel->getSubcategories() as $category) : ?>
<div class="category-landing-grid__item">
<div class="category-landing-grid__item-wrapper">
<a href="<?= $category->getUrl() ?>">
<span><?= $category->getName() ?></span>
<img src="<?= $viewModel->getCategoryImage($category) ?>" alt="<?= $category->getName() ?>"/>
</a>
</div>
</div>
<?php endforeach; ?>
</div>
I am success to get the page title, but I cannot get the category name.
model view:
public function getTitle()
{
return $this->_pageTitle->getShort();
}
phtml file:
<?php
echo $viewModel->getTitle();
?>
How do I get the parent category name for the phtml file?
I did follow the instruction from some website, but not success
https://www.mageplaza.com/devdocs/how-get-current-product-category-magento-2.html#3-steps-to-get-current-product–current-category-in-magento-2
May be it cannot be use to get the category name of Parent category (current category landing page)?