Question

I created two pages first one is "London" and other one is "Oxford". and i also created two categories with these same name."Oxford" category have identifier (ID:2) and "London" have identifier (ID:4). i putted this

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

code in oxford's content section.and

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

code in London's content section.

I want to get current category id on list.phtml.

i tried some code like

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

but it always showing category id=2 whether i am on oxford page or London page

Was it helpful?

Solution

Since the category_id is passed as a variable, so you can use following code in list.phtml file for getting the current category id.

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

We can pass variable while instantiating any block class, as each block class is a derived class of Varien_Object and In the Varien_Object class constructor , every variable that is passed in the constructor, is set as the class property. For further reference please look at lib/Varian/Varian_Object class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top