我尝试使用以下代码在magento中创建侧栏:
<?php $_helper1 = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper1->getStoreCategories(false, true, false); ?>
<div class="sidebar">
<h3>Product Categories</h3>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category); ?>">
<p><?php echo $_category->getName(); ?></p>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
我已经将我的类别设置为默认类别的子类别,并且我已经清除了我的缓存并完成了此处所述的修复:
http://www.aschroder.com/2009/03/top-3-solutions-when-your-magento-categories-are-not-displaying/
我还将Is Anchor选项设置为Yes。
但它仍然没有显示任何东西。可能有什么问题呢?
答案 0 :(得分:1)
我可以建议另一种解决方案吗?
获取类别的最佳方法是使用集合:
<?php $_categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('is_active'); ?>
<div class="sidebar">
<h3>Product Categories</h3>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_category->getUrl();?>">
<p><?php echo $_category->getName(); ?></p>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
也许这可以帮到你。