有没有办法在侧边栏中添加主导航的一部分?

问题描述 投票:0回答:1

我们的主导航中有一个“产品”类别,在此类别下面是一个下拉菜单。

我们只想从侧栏中的主导航添加“产品”类别的下拉部分。

这段代码(tnx到https://inchoo.net/magento/custom-category-menu-navigation-in-magento/)让它运转起来。但它也提供了主导航中的其他链接。

如何编辑此代码,它只显示1个类别的ID?

<ul>
<?php
    $obj = new Mage_Catalog_Block_Navigation();
    $storeCategories = $obj->getStoreCategories();
    Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
    foreach ($storeCategories as $_category):
?>
        <li>
            <strong><?php echo $_category->getName(); ?></strong>
            <?php $categoryChildren = $_category->getChildren(); ?>
            <?php if($categoryChildren->count()) : ?>
                <ul>

                    <?php foreach($categoryChildren as $_categoryChild) : ?>
                        <?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
                        <?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
                        <li>
                            <?php
                                $currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
                                echo '&emsp;' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' .  $_categoryChild->getName() . '(' . $_categoryChildModel->getProductCollection()->count() . ')</a>';
                            ?>
                        </li>
                        <?php if($categoryGrandchildren->count()) : ?>
                            <?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
                                <?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
                                <li>
                                    <?php
                                        $currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
                                        echo '&emsp;&emsp;' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' .  $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
                                    ?>
                                </li>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
        </li>
    <?php endforeach ?>
magento magento-1.9 sidebar
1个回答
1
投票
    <?php
        $obj = new Mage_Catalog_Block_Navigation();
        $storeCategories = $obj->getStoreCategories();
        Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
        foreach ($storeCategories as $_category):
    ?>
         <?php if($_category->getId() == 123) : ?>
            <li>
                <strong><?php echo $_category->getName(); ?></strong>
                <?php $categoryChildren = $_category->getChildren(); ?>
                <?php if($categoryChildren->count()) : ?>
                    <ul>

                        <?php foreach($categoryChildren as $_categoryChild) : ?>
                            <?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
                            <?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
                            <li>
                                <?php
                                    $currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
                                    echo '&emsp;' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' .  $_categoryChild->getName() . '(' . $_categoryChildModel->getProductCollection()->count() . ')</a>';
                                ?>
                            </li>
                            <?php if($categoryGrandchildren->count()) : ?>
                                <?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
                                    <?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
                                    <li>
                                        <?php
                                            $currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
                                            echo '&emsp;&emsp;' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' .  $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
                                        ?>
                                    </li>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
       <?php endif; ?>
  <?php endforeach ?>

以下部分我相信会有所帮助:123是类别ID,将其更改为您的。

<?php if($_category->getId() == 123) : ?>
© www.soinside.com 2019 - 2024. All rights reserved.