php Magento 哪个文件有导航菜单栏的代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17879795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:38:04  来源:igfitidea点击:

Magento which file have code of navigation menu bar?

phpmagento

提问by Renish Khunt

i want to edit the magento navigation menu bar code but i don't know that the which file have a menu bar code please help how can edit that file and change please help

我想编辑 magento 导航菜单条码,但我不知道哪个文件有菜单条码请帮助如何编辑该文件并更改请帮助

i want to edit menu magento provide menu like
<ul>
    <li><a href=''>Home</a></li>
    <li><a href=''>Contact Us</a></li>
    <li><a href=''>Abouty Us</a></li>

</ul>

i want to edit it like

<ul>
    <li><img src=''/><a href=''>Home</a></li>
    <li><img src=''/><a href=''>Contact Us</a></li>
    <li><img src=''/><a href=''>Abouty Us</a></li>

</ul>

i want to add image into menu and create advance menu

我想将图像添加到菜单中并创建高级菜单

采纳答案by Renish Khunt

hello friends you can also see the navigation menu bar into the navigation.php file

你好朋友你也可以看到导航菜单栏进入navigation.php文件

\app\code\core\Mage\Catalog\Block\navigation.php

\app\code\core\Mage\Catalog\Block\navigation.php

that file have a navigation menu bar code

该文件有一个导航菜单条码

回答by ermannob

You should override the _getHtml() method in Mage_Page_Block_Html_Topmenu class.

您应该覆盖 Mage_Page_Block_Html_Topmenu 类中的 _getHtml() 方法。

Here are the steps:

以下是步骤:

  1. create your app/code/local/Mage/Page/Block/Html/Topmenu/Custom.php
  2. put inside class Mage_Page_Block_Html_Topmenu_Custom extends Mage_Page_Block_Html_Topmenu
  3. copy the _getHtml() method from app/code/code/Mage/Page/Block/Html/Topmenu.php and customize it as needed
  4. edit your app/design/frontend/your_theme/default/layout/page.xml and replace <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>with <block type="page/html_topmenu_custom" name="catalog.topnav" template="page/html/topmenu.phtml"/>
  5. profit!
  1. 创建您的应用程序/代码/本地/Mage/Page/Block/Html/Topmenu/Custom.php
  2. 放进去 class Mage_Page_Block_Html_Topmenu_Custom extends Mage_Page_Block_Html_Topmenu
  3. 从 app/code/code/Mage/Page/Block/Html/Topmenu.php 复制 _getHtml() 方法并根据需要进行自定义
  4. 编辑您的 app/design/frontend/your_theme/default/layout/page.xml 并替换<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/><block type="page/html_topmenu_custom" name="catalog.topnav" template="page/html/topmenu.phtml"/>
  5. 利润!

回答by M Shahzad Khan

app\design\frontend\default\yourtheme\template\page\html\topmenu.phtml

回答by Jake Mroz

Depending on your version of Magento, this post may be out of date, so I will update. It looks like Magento made a change for this very reason to allow the customizing of that nav html.

根据您的 Magento 版本,这篇文章可能已经过时,所以我会更新。看起来 Magento 出于这个原因进行了更改,以允许自定义该导航 html。

If you look at line 80, in Mage_Page_Block_Html_Topmenu

如果你看第 80 行,在 Mage_Page_Block_Html_Topmenu

    if ($renderer = $this->getChild('catalog.topnav.renderer')) {
        $renderer->setMenuTree($this->_menu)->setChildrenWrapClass($childrenWrapClass);
        $html = $renderer->toHtml();
    } else {
        $html = $this->_getHtml($this->_menu, $childrenWrapClass);
    }

It checks to see if a render block is defined, and if not then uses a deprecated method of building the nav html

它检查是否定义了渲染块,如果没有,则使用不推荐使用的构建导航 html 的方法

/**
     * Recursively generates top menu html from data that is specified in $menuTree
     *
     * @param Varien_Data_Tree_Node $menuTree
     * @param string $childrenWrapClass
     * @return string
     * @deprecated since 1.8.2.0 use child block catalog.topnav.renderer instead
     */
    protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass)

Try this block statement in the local.xml of your theme.

在您的主题的 local.xml 中试试这个块语句。

<default>
    <reference name="catalog.topnav">
        <block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
    </reference>
</default>

Then you can pull down the template page/html/topmenu/render.phtml from the rwd theme into your own theme and make customizations without having to rewrite the block.

然后就可以将模板页面/html/topmenu/render.phtml从rwd主题下拉到自己的主题中进行自定义,无需重写块。

回答by M Shahzad Khan

Ok, replace this

好的,换这个

<li>
<a href="<?php echo $this->getBaseUrl() . $page['identifier']; ?>"><?php      echo $page['title']; ?></a>
</li>

BY

经过

 <li><img src=''/>
<a href="<?php echo $this->getBaseUrl() . $page['identifier']; ?>"><?php      echo $page['title']; ?></a>
</li>

OK here is new code, replace the whole page code with this

好的,这是新代码,用这个替换整个页面代码

<?php $_menu = $this->getHtml('level-top') ?>
 <?php if($_menu): ?>

 <?php $identifier = Mage::getSingleton('cms/page')->getIdentifier() ?>

 <?php $collection = Mage::getModel('cms/page')->getCollection()-     >addStoreFilter(Mage::app()->getStore()->getId());?>
 <?php  $collection->getSelect()
->where('is_active = 1'); ?>
<ul class="main-menu cf">
 <?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>

 <?php //make the current page active?>
<?php if($identifier == $PageData['identifier'] && $identifier != 'no-route'){ $c = 'class="active"';}else{ $c = '';}?>
<?php if($PageData['identifier']!='no-route' && $PageData['identifier']!='enable-cookies' && $PageData['identifier']!='home2') { ?>
 <li><img src=''/>
 <a <?php echo $c;?> href="<?php echo $this->getBaseUrl() . $page['identifier']; ?>"><?php       echo $page['title']; ?></a>
 </li>
 <?php } ?>
 <?php endforeach; ?>
 </ul>

style it according to yours need. By replacing classes

根据您的需要设计它。通过替换类