I want to display caregory image in my own module, so I created a module and frontend/templates/category-section.phtml, here is the code, my problem is that the source image is empty, it is in my Returns null in the module to create the page, all other similar properties work fine
I uploaded the image in the admin panel and when I click on the a tag it correctly returns the category page with the image but only in my display category and image the image is not showing
Image not shown here
If I click on any of them, the URL and the image are there, but not in the new module
<?php echo $category->getName() ?>
<section class="section-holder"> <div class="all-categories"> <p class='category-text'>categories</p> <div class='categories-flex'> <?php $categoryHelper = $this->helper('Magento\Catalog\Helper\Category'); $outputhelper = $this->helper('Magento\Catalog\Helper\Output'); foreach ($categoryHelper->getStoreCategories() as $category) : ?> <a href="<?php echo $categoryHelper->getCategoryUrl($category) ?>"> <div class='child-category'> <div> <img style="background-image: url('<?= $category->getImageUrl(); ?>');" alt=""> </div> <p> <?php echo $category->getName() ?></p> </div> </a> <?php endforeach; ?> </div> </div> </section>
Method
getStoreCategories
Does not load images for categories. It only loads attributes declared in the active module'scatalog_attributes.xml
file.You can try adding image attributes to this list by creating this file in your own module
etc/catalog_attributes.xml
Clear cache when finished.