1

我是 magento 1.7 的新手,现在正在使用名人主题我想要添加所有要在左侧栏中显示的类别,我已经浏览了 n 尝试了很多但没有一个工作(可能是由于名人主题)。所以任何人都可以尽快帮助我。请

4

1 回答 1

2

你可以像这样添加

转到您的 layout.xml 并像这样添加

/app/design/frontend/default/default/layout/catalog.xml

打开此 Xml 文件并粘贴此代码。

<reference name="left">
            <block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml" />
</reference>

打开这个文件..

/app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml

粘贴此代码:

 <?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat    = $obj->getCurrentCategory();
$current_cat    = (is_object($current_cat) ? $current_cat->getName() : '');


foreach ($store_cats as $cat) {
    if ($cat->getName() == $current_cat) {
        echo '<li class="current"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
        foreach ($obj->getCurrentChildCategories() as $subcat) {
            echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
        }
        echo "</ul>\n</li>\n";
    } else {
        echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";
    }
}
?>

编辑

列出所有类别

$_helper = Mage::helper('catalog/category') ?>

<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
    <ul>
        <?php foreach($_categories as $_category): ?>
            <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a>
                <?php //if ($currentCategory && $currentCategory->getId() == $_category->getId()): ?>
                    <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                    <?php $_subcategories = $_category->getChildrenCategories() ?>
                    <?php if (count($_subcategories) > 0): ?>
                        <ul>
                            <?php foreach($_subcategories as $_subcategory): ?>
                                <li>
                                    <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                        <?php echo $_subcategory->getName() ?>
                                    </a>

                                    <?php $_category1 = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>
                     <?php $_subcategories1 = $_category1->getChildrenCategories() ?>
                     <?php if (count($_subcategories1) > 0): ?>
                         <ul>
                             <?php foreach($_subcategories1 as $_subcategory1): ?>
                                 <li>
                                     <a href="<?php echo $_helper->getCategoryUrl($_subcategory1) ?>">
                                         <?php echo $_subcategory1->getName() ?>
                                     </a>
                                 </li>
                             <?php endforeach; ?>
                         </ul>
                     <?php endif; ?>


                                </li>
                            <?php endforeach; ?>
                        </ul>
                    <?php endif; ?>
                <?php // endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif;?>
于 2013-07-22T06:47:19.253 回答