我会问如何在magento上制作子类别。
这段代码只显示了2级的子类别,我需要进入3级。
这是我的代码
<div class="category-products <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('parent_cat_name')->toHtml() ?>">
<?php echo "<ol class='subcat_list'>"; ?>
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
// @TODO enhance for more nested category levels to display sub-categories
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
<?php echo "<ol class='subcat_list'>"; ?>
echo '<li><a href="'.$cat->getURL().'">'.$cat->getName().'</a>'.'</li>';
<?php echo "</ol>"; ?>
}
}
?>
<?php echo "</ol>"; ?>
</div>
谢谢你的帮助
发布于 2014-11-07 12:59:37
<?php $_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 $_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; ?>
发布于 2014-11-07 13:00:02
这里解释了如何以递归方式生成类别树检查这一点:http://excellencemagentoblog.com/magento-generate-category-tree-recursively
发布于 2014-11-07 17:58:36
确保您在管理面板中设置的类别级别大于3。
System -> Configuration ->目录->类别顶部导航->最大深度
https://stackoverflow.com/questions/26794317
复制相似问题