Video: Inherit images of subcategory
This video-tutorial shows you how to inherit catalog images from a parent-category in subcategories of Magento. Instead of having to give each subcategory its own image, you can save yourself time by just reusing the parent-category's image if the current category has no image of its own.
Below you can find the sample code used in this video-tutorial. It should be placed in your copy of app/design/frontend/enterprise/template/catalog/category/view.phtml.
<?php $_helper = $this->helper('catalog/output'); $_category = $this->getCurrentCategory(); $_imgHtml = ''; $_imgUrl = $_category->getImageUrl(); if (!$_imgUrl) { foreach (array_reverse($_category->getParentIds()) as $id) { if ($_imgUrl = Mage::getModel('catalog/category')->load($id)->getImageUrl()) { break; } } } if ($_imgUrl) { $_imgHtml = '<img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" class="category-image" />'; $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image'); } ?>Created on Monday, 09 November 2009
Modified on Sunday, 06 December 2009
More tutorials in this section
- Uncancelling a Magento order
- Video: Inherit images of subcategory
- Connecting to Magento with SOAP (part 4)
- Connecting to Magento with SOAP (part 3)
- Connecting to Magento with SOAP (part 2)
- Events with Magento checkout
- Connecting to Magento with SOAP (part 1)
- Setting up XFabric on Fedora Linux
