0

我创建了两个页面,第一个是“伦敦”,另一个是“牛津”。我还创建了两个具有相同名称的类别。“Oxford”类别具有标识符(ID:2),“London”具有标识符(ID:4)。我把这个

{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}

牛津内容部分中的代码。和

{{block type="catalog/product_list" category_id="4" template="catalog/product/list.phtml"}} 

伦敦内容部分的代码。

我想在 list.phtml 上获取当前类别 ID

我尝试了一些代码,例如

<?php echo $this->getLayer()->getCurrentCategory()->getId();?> 

但无论我是在牛津页面还是伦敦页面上,它总是显示类别 id=2

4

1 回答 1

0

由于 category_id 作为变量传递,因此您可以使用 list.phtml 文件中的以下代码来获取当前的类别 ID。

$current_catid=$this->getCategoryId(); // this will give your current category id

我们可以在实例化任何块类时传递变量,因为每个块类都是 Varien_Object 的派生类,并且在 Varien_Object 类构造函数中,构造函数中传递的每个变量都设置为类属性。如需进一步参考,请查看 lib/Varian/Varian_Object 类。

于 2013-03-29T11:35:58.203 回答