如何在magento左侧导航中添加悬停效果子菜单?

时间:2012-08-14 08:40:55

标签: magento navigation

我有vertnav / left.phtml文件代码,

 <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>

并设置系统&gt;配置&gt;目录&gt;类别垂直导航到2根据我的要求,但现在应该显示在显示的类别子类别上的鼠标悬停

那么如何对其进行自定义并将悬停效果代码添加到此?

请帮帮我

1 个答案:

答案 0 :(得分:0)

如果仔细查看drawOpenCategoryItem的{​​{1}},您可能会注意到该方法会检查给定类别是否属于当前类别路径。因此,只有当此检查返回Mage_Catalog_Block_Navigation时,才会呈现此类别的子类别。对于其他类别,脚本不会进入代码的那一部分。

如果我正确理解你的问题,这听起来就是这样。

true

此信息的补充。在整个PHP代码库中实际上从未调用 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>'; } } }

因此,要获得这些翻转效果,您需要拥有生成完整树结构的代码,或至少足够大的部分。关于drawOpenCategoryItem()。我猜你自己定制了吗?

为您提供一些指示。您可能想要查看以下方法。这些用于渲染顶层菜单,实际上正在执行您计划实施的任务。

System > Configuration > Catalog > Category Vertical Navigation Mage_Catalog_Block_Navigation::renderCategoriesMenuHtml()

希望这有助于你开展工作。