Magento:将子类别添加到左侧导航菜单

三磷酸腺苷

我正在使用magento。这是加载我的左侧导航栏的代码。它将主要类别加载到ol中。我还想使其加载每个li中的子类别。我在这里放置LOAD CHILD CATEGORIES的位置,我想知道php代码来获取和显示上述父类别的所有子类别。我发现了一些修复程序,但对pHp的了解不深,却导致了一系列错误。

/**
 * Category left navigation
 *
 * @see Mage_Catalog_Block_Navigation
 */


if (!Mage::registry('current_category')) {
    //no current category selected so default to showing the Products category
    $cur_category=Mage::getModel('catalog/category')->load(51);
    $layer = Mage::getSingleton('catalog/layer');
    $layer->setCurrentCategory($cur_category);
}else{
    //current category selected so display the child categories for it
    $layer = Mage::getSingleton('catalog/layer');
    $_category = $layer->getCurrentCategory();
    $currentCategoryId= $_category->getId();

    if($currentCategoryId == 306){
        //best sellers is selected so show the Product category
        $cur_category=Mage::getModel('catalog/category')->load(51);
        $layer = Mage::getSingleton('catalog/layer');
        $layer->setCurrentCategory($cur_category);
    }
}

$_categories=$this->getCurrentChildCategories();
$_count = is_array($_categories)?count($_categories):$_categories->count();
if($_count):
?>
<div class="box layered-nav">
    <div class="head">
        <h3><?php echo $this->__('Browse By') ?> PRODUCT CATEGORY</h3>
    </div>
    <div class="border-creator">
        <div class="narrow-by">
            <dl id="narrow-by-list">
                <dd>
                    <ol>
                    <?php foreach ($_categories as $_category): ?>
                        <?php if($_category->getIsActive()): ?>
                        <li>                        
                            <a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="active"<?php endif ?>><?php echo $this->htmlEscape($_category->getName()) ?></a>
                        **LOAD CHILD CATEGORIES IN HERE**
                        </li>
                        <?php endif; ?>
                    <?php endforeach ?>
                    </ol>
                </dd>
            </dl><script type="text/javascript">decorateDataList('narrow-by-list')</script>
        </div>
    </div>
</div>
<?php
endif; 
?>
<!-- [ends] .browse-by // -->

到目前为止,我想出的最好的方法,我知道并不多

<ul class="subnav">
<li><a></a>
</ul>

我非常感谢您的帮助

尚兹

检查以下代码

 <?php $_helper = Mage::helper('catalog/category'); 
 $_categories = $_helper->getStoreCategories(); 
 $currentCategory = Mage::registry('current_category') ;
 if (count($_categories) > 0): ?>
    <ul>
        <?php foreach($_categories as $_category): ?>
            <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a>
                <?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>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

现在$_subcategories = $_category->getChildrenCategories()获取所有子类别。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

标签导航(将类添加到打开的项目菜单)

来自分类Dev

将个人资料图片添加到引导导航栏下拉菜单

来自分类Dev

将子类对象添加到ArrayList

来自分类Dev

Magento将Flexslider添加到主页

来自分类Dev

将类别添加到自定义帖子类型并根据类别显示

来自分类Dev

将声明添加到ApplicationUser的子类

来自分类Dev

将更多项目添加到菜单时,将内容div的高度扩展到左侧菜单的高度

来自分类Dev

Woocommerce以编程方式将产品添加到类别和子类别

来自分类Dev

使用JavaSCript将活动类动态添加到动态构建的导航菜单项

来自分类Dev

如何将父类别添加到子类别php

来自分类Dev

将类别添加到所选选项

来自分类Dev

将类别添加到所选选项

来自分类Dev

将类别添加到4级超级菜单的每个子菜单级别

来自分类Dev

将具有特定类别的文本添加到下拉菜单<select>

来自分类Dev

Magento将自定义链接添加到导航菜单

来自分类Dev

如何将子菜单添加到导航菜单

来自分类Dev

Magento:将CSS添加到主题

来自分类Dev

将下拉菜单添加到导航栏

来自分类Dev

Magento将Flexslider添加到主页

来自分类Dev

Woocommerce将类别添加到标签

来自分类Dev

将CSS添加到用户magento

来自分类Dev

将新创建的列表添加到Sharepoint左侧导航的“最近”

来自分类Dev

Android-无法将项目添加到导航视图菜单的顶部

来自分类Dev

将菜单添加到导航栏的 Javascript

来自分类Dev

Magento 2 将产品添加到类别(代码)

来自分类Dev

将子类别添加到 Laravel 5.4

来自分类Dev

将标签类添加到导航菜单中的当前 Woocommerce 产品类别

来自分类Dev

将“重复”添加到自定义帖子类型管理菜单

来自分类Dev

将下拉菜单添加到 bootstrap3 导航栏

Related 相关文章

热门标签

归档