magento想要编辑"目录类别链接"小部件以显示特定类别的图像。我尝试编辑"类别/小部件/链接/link_block.phtml"
<?php
$_category = $this->getCurrentCategory();
?>
<span class="widget widget-category-link">
<a <?php echo $this->getLinkAttributes() ?>>
<span><?php echo $this->htmlEscape($this->getAnchorText()) ?></span>
<img src="<?php echo $_category->getImageUrl();?>" />
</a>
<br/>
</span>
您需要
覆盖Mage_Catalog_Block_Widget_Link
块。按照以下步骤在小部件中获取类别图像:
- 复制此文件:
appcodecoreMageCatalogBlockWidgetLink.php
- 过去此文件:
appcodelocalMageCatalogBlockWidgetLink.php
将以下代码添加到
appcodelocalMageCatalogBlockWidgetLink.php
文件中public function getImage(){ $imgPath = ''; if ($this->_entityResource) { $idPath = explode('/', $this->_getData('id_path')); if (isset($idPath[1])) { $id = $idPath[1]; if ($id) { $imgPath = Mage::getBaseUrl('media').'catalog/category/'.$this->_entityResource->getAttributeRawValue($id, 'image', Mage::app()->getStore()); } } } return $imgPath; }
更新了以下
category/widget/link/link_block.phtml
代码<?php $_category = $this->getCurrentCategory(); ?> <span class="widget widget-category-link"> <a <?php echo $this->getLinkAttributes() ?>> <span><?php echo $this->htmlEscape($this->getAnchorText()) ?></span> <img src="<?php echo $this->getImage();?>" /> </a> <br/> </span>
希望它能有所帮助!