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.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-628380ce8fe9f748951812/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...