Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Get current category id in list.phtml
 
Bart00
Jr. Member
 
Total Posts:  3
Joined:  2009-10-05
 

I want to show two specific categories on all other category pages, so I wrote this in the end of /template/catalog/product/list.phtml:

<?php 
$thisCat 
= ???;
$showAlways = array(79);
if (!
in_array($thisCat$showAlways)) {
  
foreach($showAlways as $catId{
    $cat 
Mage::getModel('catalog/category')->load($catId);
    
    echo 
"<div class='category-head'><h2>".$cat->getName()."</h2></div>";
    echo 
"<p class='category-description'>".$cat->getDescription()."</p>";
  
    echo 
$this->getLayout()->createBlock('catalog/product_list')->setCategoryId($catId)->setTemplate('catalog/product/list.phtml')->toHtml();
  
}
}
?>

What should I write in the place of ??? in order to get the current category ID and to prevent an endless loop?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bart00
Jr. Member
 
Total Posts:  3
Joined:  2009-10-05
 

This unfortunately also results in an endless loop, as it returns the ID of the category requested, rather than the one being processed in the file… Any other sollutions?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Adam Moss
Sr. Member
 
Avatar
Total Posts:  248
Joined:  2009-02-11
Birmingham, UK
 

I used this code:

<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getName(); ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top