Php Magento:在子类别页面上显示左侧类别导航

Php Magento:在子类别页面上显示左侧类别导航,php,magento,Php,Magento,我正在使用Magento Porto主题,需要在子类别页面上显示左侧类别导航(category_nav.html)。我设法让它显示在子类别页面上,但不知道如何通过那里 这是我目前的代码: <?php $_categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('*') ->addAt

我正在使用Magento Porto主题,需要在子类别页面上显示左侧类别导航(category_nav.html)。我设法让它显示在子类别页面上,但不知道如何通过那里

这是我目前的代码:

    <?php
        $_categories = Mage::getModel('catalog/category')->getCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('level', 2)
            ->addAttributeToFilter('is_active', 1);
    ?>

    <?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
    <?php
        function cmpCatPosition($a, $b) {
            if ($a->position == $b->position)
                return 0;
            return ($a->position > $b->position) ? 1 : -1;
        }
        function getChildrenCategoriesHtml($_category){
            $children = explode( ",", $_category->getChildren() );
            //usort($children, 'cmpCatPosition');
            $content = '';
            $content .= '<li class="';
            if(!$children[0])
                $content .= 'has-no-children';
            else
                $content .= 'has-children';
            $content .= '">';
            $content .= '<a href="'.$_category->getUrl().'" ';
            $content .= '>'.$_category->getName().'</a>';
            if($children[0]){
                $content .= '<a href="javascript:void(0)" class="plus"><i class="icon-plus-squared"></i></a>';
                $content .= '<ul>';
                foreach($children as $child){
                    $_subcat = Mage::getModel( 'catalog/category' )->load( $child );
                    $content .= getChildrenCategoriesHtml($_subcat);
                }
                $content .= '</ul>';
            }
            $content .= '</li>';
            return $content;
        }
    ?>
    <?php if($_count): ?>
    <div class="block block-category-nav">
        <div class="block-title">
            <strong><span><?php echo Mage::registry('current_category')->getName(); ?></span></strong>
        </div>
        <div class="block-content">
            <ul class="category-list">
            <?php foreach ($_categories as $_category): ?>
                <?php
                if($_category->getIsActive()){
                    echo getChildrenCategoriesHtml($_category);
                }
                ?>
            <?php endforeach ?>
            </ul>
        </div>
    </div>



我编写的代码实际上是有效的。我只是错过了在后端添加“Is Anchor->Yes”

有一段代码可以全局执行,但我想控制显示什么和不显示什么,所以在锚上选择是/否可以解决问题


这不是编程问题。

关于如何用纯PHP重现这一点的示例会很好,否则就是“为我做”。我认为这与我发布的代码顶部的过滤有关。我没有要求任何人为我做任何事。让我看看我错过了什么。这段代码的大部分对于我试图实现的函数甚至都不是必需的。我只是添加了它,以便有人可以获得完整的范围。