2014-09-30 71 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>'; 
     } 

希望這有助於。