Let’s initiate a discussion!!
If you want to show sub category image with sub category name of current category page then follow below process.
Get subcategory of current category
Step 1 : create sub-category.phtml file under ../app/design/frontend/[VendorName]/[theme]/Magento_Catalog/templates/category/
and paste below code inside it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category'); //get current category $subcategories = $category->getChildrenCategories(); $_helper = $this->helper('Magento\Catalog\Helper\Output'); ?> <ul class="sub-category"> <?php foreach ($subcategories as $sub_category) { $_category = $objectManager->create('Magento\Catalog\Model\Category')->load($sub_category->getId()); $_outputhelper = $this->helper('Magento\Catalog\Helper\Output'); $subcategoryurl = $sub_category->getUrl(); $catimgHtml = ''; echo '<li>'; if ($catimgUrl = $_category->getImageUrl()) { $catimgHtml = '<img src="' . $catimgUrl . '" />'; $catimgHtml = $_outputhelper->categoryAttribute($_category, $catimgHtml, 'image'); /* @escapeNotVerified */ echo '<a href="' . $subcategoryurl . '" title="' . $sub_category->getName() . '">' . $catimgHtml . '</a>'; } echo '<h2><a href="' . $subcategoryurl . '" title="' . $sub_category->getName() . '">' . $sub_category->getName() . '</a></h2>'; echo '</li>'; } ?> </ul> |
Step 2 : Add below mention code in ../app/design/frontend/[VendorName]/[theme]/Magento_Catalog/layout/catalog_category_view.xml
1 2 3 4 5 |
<referenceContainer name="columns.top"> <!-- Add this below code --> <container name="category.view.customcatlink" htmlTag="div" htmlClass="custom-category-link" before="category.view.container"> <block class="Magento\Catalog\Block\Category\View" name="custom.category.links" template="Magento_Catalog::category/custom-cat-links.phtml"/> </container> |
After that run below commands
– php bin/magento setup:upgrade
– php bin/magento setup:di:compile
– php bin/magento cache:clean
That’s it.
Now, sub category image with sub category name will show on list page.
[crayon-641f004400647882467396/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.