0

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

并根据我的要求将 System > Configuration > Catalog > Category Vertical Navigation 设置为 2,但现在鼠标悬停在显示的类别子类别上时应该显示

那么我该如何对其进行自定义并为此添加悬停效果代码呢?

请帮我

4

1 回答 1

0

If you take a closer look at the drawOpenCategoryItem of the Mage_Catalog_Block_Navigation you might notice that the method does a check whether the given category is part of the current category path. So only when this check returns true, the children categories of this category will be rendered. For other categories the script will not go into that part of the code.

This sounds to be case if I understand your question correctly.

    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>';
            }
        }
    }

Additional to this information. The drawOpenCategoryItem() is never actually called upon in the whole PHP codebase.

So to have these rollover effects you need to have code that generates the full tree structure, or at least a big enough part of it. Regarding the System > Configuration > Catalog > Category Vertical Navigation. I guess you customized that yourself?

To give you a few pointers. You might want to have a look at the following methods. These are used for the rendering of the top menu and are actually doing the thing you are planning to implement.

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

Hopes this helps you getting things underway.

于 2012-08-14T18:45:39.963 回答