如何使用Magento块显示多个类别
我的Magento主页目前有这个代码片段,可以很好地显示所有产品如何使用Magento块显示多个类别,magento,Magento,我的Magento主页目前有这个代码片段,可以很好地显示所有产品 {{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}} 大致上,我的分类树与此类似 id 2 (root cat) -> id 3 -> id 4 -> id 5 因为我添加的每个产品都是id为2的子产品,所以每个产品都会显示在主页上。我想要的是一个解决方案,它允许我从主页产品列表
{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}
大致上,我的分类树与此类似
id 2 (root cat)
-> id 3
-> id 4
-> id 5
因为我添加的每个产品都是id为2的子产品,所以每个产品都会显示在主页上。我想要的是一个解决方案,它允许我从主页产品列表中排除特定id(类别)
我尝试了下面的这个片段,但没有成功:
{{block type="catalog/product_list" category_id="2,3,5" template="catalog/product/list.phtml"}}
代码
{{block type=“catalog/product\u list”category\u id=“2,3,5”template=“catalog/product/list.phtml”}
无法工作,因为块Mage\u catalog\u block\u product\u list只加载一个类别$category=Mage::getModel('catalog/category')->load($this->getCategoryId())代码>
我为您的问题找到了两种解决方案,您可以使用不同类别id多次使用该块:
{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}
{{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}}
{{block type="catalog/product_list" category_id="5" template="catalog/product/list.phtml"}}
或覆盖块图像目录块产品列表并更改此零件的行为
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
谢谢你的回答。我将在以后使用这种方法——就目前而言——时间不在我这边。谢谢