2014-09-30 77 views
0

我一直在尝试向我的magento网站的导航栏添加Javascript:void(0)很长一段时间。 我读了很多关于这个主题的文章,几乎所有人都说我应该编辑magento javascript:void导航菜单中的void(0)

/app/code/core/Mage/Catalog/Block/Navigation.php或者将其复制到本地文件夹结束编辑。

这里我遵循的一种流行的方式;

To remove url, href functionality of the top menu categories, you can take the following steps: 

Create some folder as this path: app/code/local/Mage/Catalog/Block 
Copy file Navigation.php from app/code/core/Mage/Catalog/Block to 
app/code/local/Mage/Catalog/Block 
Go to function _renderCategoryMenuItemHtml() 
Replace this code 

$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>'; 
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>'; 
$html[] = '</a>'; 
with this code 

if($category->getLevel()== 2 && $hasActiveChildren) { 
     $html[] = '<a href="[removed]void(0);"'.$linkClass.'>'; 
     $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>'; 
     $html[] = '</a>'; 
} else { 
     $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>'; 
     $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>'; 
     $html[] = '</a>'; 
} 

但它没有为我工作。奇怪的是,即使我删除/app/code/core/Mage/Catalog/Block/Navigation.php导航菜单工作得很好。如果它得到了工作代码,我不知道。

也许你有一个想法,可以帮助我。我只想将Javascript:void(0)添加到导航菜单中。

+0

你确定你没有得到一个缓存版本?你确定你的代码被使用了吗?您可以更改php的输出以确保:'$ html [] ='已更改:'。 $ this ...'你可以安装一个叫做缓存杀手的chrome扩展,但是也许PHP也会缓存一些东西,所以重新启动httpd并且删除服务器上的缓存文件。 – HMR 2014-09-30 04:36:45

回答

0

我觉得这是缓存或Magento编译器的问题。我建议你从magento admin执行以下步骤。

  1. admin->System->Cache Management和透明/冲洗所有缓存

  2. admin->System->Tools->Compilation。检查编译启用然后再禁用它,清除缓存和运行编译过程

0

我也一直在寻找解决这个问题,我认为这个问题是你链接的代码仅适用于1.7,而不是1.9 ?

我想出了

副本Topmenu.phpapp\code\core\Mage\Page\Block\Htmlapp\code\local\Mage\Page\Block\Html解决方案上线131取代:

$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; 
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' 
      . $this->escapeHtml($child->getName()) . '</span></a>'; 

 if ($child->hasChildren()) { 
      $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; 
      $html .= '<a href=\'javascript:void(0);\'><span>' 
       . $this->escapeHtml($child->getName()) . '</span></a>'; 
     } 
     else{ 

      $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>'; 
      $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' 
      . $this->escapeHtml($child->getName()) . '</span></a>'; 
     } 

希望这有助于。