I would like certain categories to show a listing of subcategories above the products. My current template looks like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
$subcats = $category->getChildrenCategories();
    <?php foreach ($subcats as $subcat) : ?>
        <?php if ($subcat->getIsActive()) : ?>
                <a href="<?php echo $subcat->getUrl(); ?>" class="block-promo" title="<?php echo $subcat->getName() ?>"><?php echo $subcat->getName() ?></a>
        <?php endif ?>
    <?php endforeach ?>

I've tried replacing $subcat->getName() with $subcat->getMetaTitle(), hoping some hidden accessor would do its magic, but to no avail.


Following the answer provided, I created a new block:

use Magento\Framework\Registry;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

class SubcategoryListing extends Template
    protected $_objectManager;
    protected $_registry;

    * @param Context $context
    * @param Registry $registry
    * @param ObjectManagerInterface $objectManager
    * @param array $data
    public function __construct(
        Context $context,
        Registry $registry,
        ObjectManagerInterface $objectManager,
        array $data = []
        parent::__construct($context, $data);
        $this->_objectManager = $objectManager;
        $this->_registry = $registry;

    * Retrieve child store categories
    public function getSubcategoryListing()
        $repo = $this->_objectManager->get('Magento\Catalog\Model\CategoryRepository');
        $category = $repo->get($this->_registry->registry('current_category')->getId());
        $subcategories = $category->getChildrenCategories();

        foreach ($subcategories as $subcategory) {
            yield $repo->get($subcategory->getId());

I then changed the template to:

    <div class="row">
<?php $subcats = $block->getSubcategoryListing(); ?>
<?php foreach ($subcats as $subcat) : ?>
    <?php if ($subcat->getIsActive()) : ?>
            $_url = $subcat->getUrl();
            $_name = $subcat->getName();
            $_title = $subcat->getMetaTitle();
        <div class="col-md-4 text-center">
            <div class="well">
                <a href="<?php echo $_url; ?>" title="<?php echo $_name ?>">
                    <?php echo $_title != '' ? $_title : $_name ?>
    <?php endif ?>
<?php endforeach ?>
    <br class="clearfix" />

This gave me the exact functionality I needed, plus it cleaned up the template quite a bit.

1 Answer 1


Catalog categories are implemented as EAV-based models in Magento 2. What is likely happening is that the meta_title attribute isn't included in the initial load of the catalog category model in this case, for whatever reason. Therefore, you'll want to reload the category model, and that should include the missing attribute.

A good way to do this is in the block, with the category repository interface's getById() method. However, if you can't create a new block, then you can reload the category in your template: $subcat->load($subcat->getId(). That should do it.

The best way would be to declare a plugin before the Magento\Catalog\Model\ResourceModel\Category::getChildrenCategories() method that adds the attribute to the model's collection, which becomes the collection that is returned to include that attribute.

Please let me know if you have any questions.

  • I added a block that fully loads the subcategories via the repository, see my edit for the code and let me know if you have any suggestions/improvements. Commented Dec 5, 2016 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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