2012-08-14 53 views
0

我已經vertnav/left.phtml文件代碼,如何在magento的左側導航中添加懸停效果的子菜單?

<div class="vertnav-container"> 

<div class=""> 

    <h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4> 

<?php $store_categories = $this->toLinearArray($this->getStoreCategories()) ?> 

    <?php if ($count = count($store_categories)): ?> 

    <ul id="vertnav"> 

    <?php endif; ?> 
    <?php foreach ($store_categories as $i => $_category): ?><?php $class = array() ?> 
    <?php if ($count == 1): ?> 
    <?php $class[] = 'only' ?> 
    <?php elseif (! $i): ?> 
    <?php $class[] = 'first' ?> 
    <?php elseif ($i == $count-1): ?> 
      <?php $class[] = 'last' ?> 
    <?php if (isset($store_categories[$i+1]) && $this->isCategoryActive($store_categories[$i+1])) $class[] = 'prev'; ?> 
<?php if (isset($store_categories[$i-1]) && $this->isCategoryActive($store_categories[$i-1])) $class[] = 'next'; ?> 
    <?php echo $this->drawOpenCategoryItem($_category, 0, $class) ?> 
    <?php endforeach ?> 
    <?php if ($count): ?> 
    </ul> 
<?php endif; ?> 
</div> 
</div> 

,並設置系統>配置>目錄>類別垂直導航至2,符合我的要求,但現在上顯示的類別的子類別鼠標懸停應顯示

那麼我如何做到這一點,並添加懸停效果代碼到這個?

請幫我

回答

0

如果你看看的drawOpenCategoryItem仔細看看Mage_Catalog_Block_Navigation您可能會注意到,該方法不檢查給定的類別是否是當前類路徑的一部分。所以只有當這個檢查返回true,這個類別的子類別將被渲染。對於其他類別,腳本不會進入代碼的那部分。

這聽起來是如果我正確理解你的問題的情況下。

if (in_array($category->getId(), $this->getCurrentCategoryPath())){ 
     $children = $category->getChildren(); 
     $hasChildren = $children && $children->count(); 

     if ($hasChildren) { 
      $htmlChildren = ''; 
      foreach ($children as $child) { 
       $htmlChildren.= $this->drawOpenCategoryItem($child); 
      } 

      if (!empty($htmlChildren)) { 
       $html.= '<ul>'."\n" 
         .$htmlChildren 
         .'</ul>'; 
      } 
     } 
    } 

此信息的補充。在整個PHP代碼庫中實際上都沒有調用drawOpenCategoryItem()

所以要有這些翻轉效果,你需要有代碼來生成完整的樹結構,或者至少有足夠大的一部分。關於System > Configuration > Catalog > Category Vertical Navigation。我想你自己定製了嗎?

給你幾點提示。你可能想看看下面的方法。這些用於頂層菜單的渲染,並且實際上正在執行您計劃實施的內容。

Mage_Catalog_Block_Navigation::renderCategoriesMenuHtml() Mage_Catalog_Block_Navigation::_renderCategoryMenuItemHtml()

希望這有助於你把事情正在進行中。