I want to display the category image of the category.I have a phtml file and is called in cms home page.
<?php
$subcats = array(99,189);
$imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Category\ListProduct');
foreach($subcats as $cat_id){
//echo $cat_id;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->create('Magento\Catalog\Model\Category')->load($cat_id);
$categoryImage = $imageBlock->getImage($category, 'category_page_list');
echo 'dfdf'.$category->getName();
//$productImage = $imageBlock->getImage($category);
echo 'ssds'.$categoryImage;
}
But it is not displaying the image and getting an error.
Please help.
Best Answer
I have Used This code to get Category images in my code Please look at these