简体   繁体   English

如何在 Magento > 1.7 中向导航添加类别图像/缩略图

[英]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.

相关问题 在Magento 1.7中显示导航中每个类别的畅销书 - Showing bestseller of each category in navigation in Magento 1.7 Magento导航菜单栏,带缩略图 - Magento Navigation Menu Bar With Thumbnail image 如何在Magento中将产品缩略图添加到订单审核页面? - How to add product thumbnail image to order review page in Magento? Prestashop 1.7 添加<br>类别名称中的特殊字符标记但无效,如何在菜单导航导航中拆分字符串? - Prestashop 1.7 add <br> special character tag in category name but invalid , how to split string in menu navigation nav? 在Magento导航菜单中显示带有图像缩略图的子类别描述 - Show subcategory description in Magento navigation menu with image thumbnail 如何以编程方式向Magento添加类别和类别路径? - How to add a category and category path to Magento programatically? 如何在magento中编辑类别导航设计 - How to edit category navigation design in magento 如何在Magento中使用getThumbnailUrl()从类别显示缩略图 - how to display thumbnail from category using getThumbnailUrl() in Magento Magento:如何通过另一个类别过滤当前类别-分层导航 - Magento: How to filter current category by another category - layered navigation 如何使用Magento类别链接创建自定义导航 - Magento 1.9 - How to create custom navigation using Magento category links - Magento 1.9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM