Magento 有没有办法在侧边栏中添加主导航的一部分?
我们在主导航中有一个类别“产品”,该类别下有一个下拉菜单 我们只想在侧栏的主导航中添加“产品”类别的下拉部分 此代码(tnx to)使其正常工作。但它也提供了主导航中的其他链接 如何编辑此代码,使其仅按ID显示1个类别?Magento 有没有办法在侧边栏中添加主导航的一部分?,magento,magento-1.9,sidebar,Magento,Magento 1.9,Sidebar,我们在主导航中有一个类别“产品”,该类别下有一个下拉菜单 我们只想在侧栏的主导航中添加“产品”类别的下拉部分 此代码(tnx to)使其正常工作。但它也提供了主导航中的其他链接 如何编辑此代码,使其仅按ID显示1个类别? <ul> <?php $obj = new Mage_Catalog_Block_Navigation(); $storeCategories = $obj->getStoreCategories(); Mage::registr
<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 ' ' . '<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 '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
?>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach ?>
-
-
-
-
-
我相信下面的部分会有所帮助:123是类别ID,将其更改为您的
<?php if($_category->getId() == 123) : ?>
实际上,最好不要加载所有类别,然后循环它们,我认为您也可以得到所需的类别,我可以解释,但如果这足够好,请使用if语句:)请解释。我试着添加你的代码,它成功了。但如果有更好的方法…:我仔细研究了一下,也许这是一个比我想象的更好的方法。要加载单个类别,可以使用xml,如:。但如果它能工作并且页面加载良好,我不会担心:)我会让它保持这种方式,它能工作。谢谢你的帮助和时间!
<?php if($_category->getId() == 123) : ?>