Php 如何获取当前Catagory id?
我有一个CMS页面,我将在该页面上显示带有以下更新XML代码的产品:Php 如何获取当前Catagory id?,php,xml,variables,layout,magento,Php,Xml,Variables,Layout,Magento,我有一个CMS页面,我将在该页面上显示带有以下更新XML代码的产品: <reference name="content"> <block type="catalog/product_list" name="product_list" template="catalog/product/wholesale-list.phtml"> <action method="setCategoryId"><category_id>191
<reference name="content">
<block type="catalog/product_list" name="product_list" template="catalog/product/wholesale-list.phtml">
<action method="setCategoryId"><category_id>191</category_id></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
及
但这两种方法都不起作用。有人知道我如何获得ID吗?您是否考虑过更新目录页面的布局而不是制作CMS页面?我想在某些情况下,您可能更喜欢CMS页面,但您可以相当轻松地更新类别的布局,就像在Magento中一样简单,但这并不是那么容易:) 登录到管理后端,转到目录->管理类别,然后选择所需类别,然后单击自定义设计选项卡。请注意“自定义布局更新”字段。这是您可以放置布局更新的地方 所以对于这个类别,如果你不想显示一个特定的块,你可以这样做
<reference name="right">
<remove name="right.permanent.callout" />
</reference>
这将从布局中删除名为right.permanent.callout的块。如果您只想更改产品列表以使用特定的phtml文件,您可以执行以下操作
<reference name="product_list">
<action method="setTemplate"><template>catalog/product/wholesale.phtml</template></action>
</reference>
目录/产品/批发.phtml
您可能可以使用谷歌来了解更多关于如何布局的信息。还没有尝试过这一点,但可能类似于:
$this->getLayout()->getBlock('product_list')->getCategoryId()
通过这种方式,您可以直接获得在XML中的块对象上设置的变量
干杯,JD这对我来说很有用:
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$currentCategoryId= $_category->getId();
我认为这是最好的办法;) 试试下面的代码
Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
这对我很有用:
$currentCat = $this->getLayout()->getBlock('category.products')->getCurrentCategory();
然后将当前类别作为对象,可以通过以下方式获取id:
$currentCat->getId();
这是正确的答案,应该标记为:)@ShivSingh基本上在脚本上方,以获取最后访问的分类库@Jonathan Day,它对我有效<代码>Mage::注册表('current_category')->getId()代码>当我们从cms页面或cms静态块调用产品时,此函数不起作用。
Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$currentCat = $this->getLayout()->getBlock('category.products')->getCurrentCategory();
$currentCat->getId();