如何显示Magento导航菜单中未包含的类别?
<?php $_subcategories = $_category->getChildrenCategories(); ?>
<li>
<a <?php if (count($_subcategories) > 0){ ?>
href='#'
<?php }else { ?>
href="<?php echo $_helper->getCategoryUrl($_category)?>"
<?php }?>
<?php echo $_category->getName() ?></a>
</li>
<?php } ?>
答案 0 :(得分:4)
$collection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1) //only active categories
->addAttributeToFilter('include_in_menu', 0)
->addAttributeToSort('position');//sort by position
foreach ($collection as $category) {
//do something with $category
}
答案 1 :(得分:2)
在类别集合中,您必须检查它是否包含在导航菜单中
if (!$_category->getIncludeInMenu()) {
// your code here
}
以下是使其正常运行的代码 -
foreach($_subcategories->getData() as $category) {
$subcatid = $category['entity_id'];
$_cat = Mage::getModel('catalog/category')->load($subcatid);
if (!$_cat->getIncludeInMenu()) {
echo $_cat->getName();
}
}