[英]How to add category image/thumbnail to navigation in Magento > 1.7
I've seen a few solutions to this funcionality request for versions of Magento < 1.7 but none for the version I am using.我已经看到了一些针对 Magento < 1.7 版本的功能请求的解决方案,但没有针对我使用的版本。 Since in v1.7 the navigation template was moved from
top.phtml
to \\app\\design\\frontend\\THEME\\TEMPLATENAME\\template\\page\\html\\topmenu.phtml
the solutions I have seen are no longer applicable.由于在
top.phtml
导航模板从top.phtml
移动到\\app\\design\\frontend\\THEME\\TEMPLATENAME\\template\\page\\html\\topmenu.phtml
,我看到的解决方案不再适用。
I just want to be able to output the category image (uploaded through the admin interface) within the native category menu dropdown.我只是希望能够在本机类别菜单下拉列表中输出类别图像(通过管理界面上传)。 The dropdown structure and layout is done and works as I want it, minus the image.
下拉结构和布局已完成并按我想要的方式工作,减去图像。
You will need to override / replace Mage_Catalog_Model_Observer.您将需要覆盖/替换 Mage_Catalog_Model_Observer。
Simplest way is to copy Mage_Catalog_Model_Observer (app/code/core/Mage/Catalog/Model/Observer.php) to:最简单的方法是将 Mage_Catalog_Model_Observer (app/code/core/Mage/Catalog/Model/Observer.php) 复制到:
app/code/local/Mage/Catalog/Model/Observer.php
You can then modify: _addCategoriesToMenu()然后您可以修改: _addCategoriesToMenu()
Add the image into the data:将图像添加到数据中:
$categoryData = array(
'image_url' => $category->getImageUrl(), // or thumbnail if you wanted.
'name' => $category->getName(),
'id' => $nodeId,
'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category)
);
this data will then be available inside the Navigation block.然后,这些数据将在导航块内可用。 you will also need to override this block: copy app/code/core/Mage/Catalog/Block/Navigation.php to
您还需要覆盖此块:将 app/code/core/Mage/Catalog/Block/Navigation.php 复制到
app/code/local/Mage/Catalog/Block/Navigation.php
modify the _getHtml() method to add the image into the markup as required.修改_getHtml()方法以根据需要将图像添加到标记中。
the image url will be available via the node, like this:图像 url 将通过节点可用,如下所示:
$child->getImageUrl(); // or
$child->getData('image_url');
This solution is for Magento -1.8.*此解决方案适用于 Magento -1.8.*
In Model file.在模型文件中。 (/app/code/core/Mage/Catalog/Model/Observer.php)
(/app/code/core/Mage/Catalog/Model/Observer.php)
Update following code in Function Name: _addCategoriesToMenu更新函数名称中的以下代码:_addCategoriesToMenu
$categoryData = array(
'name' => $category->getName(),
'id' => $nodeId,
'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'thumbnail' => Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()
);
Then go into Html folder.然后进入Html文件夹。 (app/code/core/Mage/Page/Block/Html/Topmenu.php)
(app/code/core/Mage/Page/Block/Html/Topmenu.php)
Update the following line of code at line 128 in在第 128 行更新以下代码行
Function name: _getHtml函数名:_getHtml
$urls = Mage::getBaseUrl('media').'catalog/category/'.$child->getData('thumbnail');
$img = '<img src="'.$urls.'" />';
$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . ' </span> '.$img.' </a>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.