左侧边栏类别导航在Magento的最后一级类别页面上消失

时间:2014-02-18 23:26:38

标签: magento navigation anchor categories sidebar

在最低的类别级别,我的侧边栏在Magento中消失了。对于我的所有类别,Anchor设置为no。最终,我想在侧栏上显示所有主要类别(显然在每个产品页面上)和主要类别内的子类别。

不确定是什么问题。相当多的基础magento代码与一些风格的变化。非常感谢任何帮助!

<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
    <aside id="sidebar">
        <div class="sidebar-nav">
            <h2><?php echo $this->__('Products') ?></h2>
            <ul>
                <?php foreach ($_categories as $_category): ?>
                    <?php if($_category->getIsActive()): ?>
                    <li>
                        <a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
                    </li>
                    <?php endif; ?>
                <?php endforeach ?>
            </ul>
        </div>
        <div class="sidebar-nav">
            <h2 class="red">Holiday</h2>
            <ul>
                <li><a href="#">Christmas</a></li>
                <li><a href="#">Halloween</a></li>
                <li><a href="#">Thanksgiving</a></li>
                <li><a href="#">Easter</a></li>
                <li><a href="#">4th of July</a></li>
                <li><a href="#">Valentine's Day</a></li>
            </ul>
        </div>
        <div class="sidebar-nav">
            <h2>About Us</h2>
            <ul>
                <li><a href="#">About Mary</a></li>
                <li><a href="#">Press</a></li>
                <li><a href="#">Licensing</a></li>
                <li><a href="#">Shows</a></li>
                <li><a href="#">Custom Work</a></li>
                <li><a href="#">Contact Us</a></li>
                <li><a href="#">Privacy Policy</a></li>
                <li><a href="#">Terms &amp; Conditions</a></li>
            </ul>
        </div>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
<?php endif; ?>
    </aside>

1 个答案:

答案 0 :(得分:1)

由于您的代码正在使用,它们正在您的最低类别中消失:

<?php $_categories = $this->getCurrentChildCategories() ?>

如果您当前的类别(您当前正在查看的类别)没有子类别,则该块不会显示任何类别(因为getCurrentChildCategories()会返回当前类别的子类别)

左侧类别的行为会有所不同,具体取决于Is Anchor是设置为是还是否。

  1. 类别设置为Is Anchor: Yes
    - 左侧类别将用作过滤器,而不是直接导航链接。当您单击左侧的类别时,您将保持与您正在查看的相同类别,但页面上的结果将被过滤到所选类别。

  2. 类别设置为Is Anchor: No
    - 左侧类别将用作菜单。选择类别后,用户将被带到该实际类别页面。如果他们导航到的类别页面没有子类别,则左侧不会显示任何类别。

  3. 因此,在您的情况下,您可以将上级类别设置为Is Anchor: Yes,最低类别将作为过滤器而不是菜单链接。

    如果您希望人们导航到最低级子类别,则必须修改模板用于从父类别中提取类别的功能。 StackOverflow上有几篇文章已经详细说明了如何做到这一点。

相关问题