0

I have a little problem, I don't know how to solve it. My problem is I want get category id by the page layout selection. For example from admin I have created new layout 'category-like'. just like other layouts, 1-colomn, 2-colomns-with-left-bar .. So now I want get which categories are used this layout. If two categories are used this layout mens, then I need that category id ...Please help me guys..

Update:

At least please tell me, how get page layout name from category id ...

1 Answer 1

2

list.phtml

Get the layout of Current Category

$yourCatId = $this->getCategoryId(); 
echo $this->getLayout()->getBlock('root')->getTemplate($yourCatId);

This is to get list of all category and there layouts:

$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url')
->addAttributeToSelect('is_active');

foreach ($categories as $category)
{
    if ($category->getIsActive()) { // Only pull Active categories
        $entity_id = $category->getId();
        echo $this->getLayout()->getBlock('root')->getTemplate($entity_id);

    }
}
7
  • Thanks for for answer, But I want get that id from outside, not in list.phtml file...
    – Elavarasan
    Commented Jun 23, 2014 at 11:45
  • I have update the code a bit, this will give you all categories with there layouts, hope this is what you want Commented Jun 23, 2014 at 11:47
  • You can get the current category in any view, block, model or controller file, by calling Mage::registry('current_category');
    – Alex Dinca
    Commented Jun 23, 2014 at 11:52
  • 1
    @alex.ayg I guess, This works only for product view page Commented Jun 23, 2014 at 11:57
  • @TBIInfotech this works when category or product controller actions are called (i.e. category view, product view) http://svn.magentocommerce.com/source/branches/1.8/app/code/core/Mage/Catalog/controllers/CategoryController.php _initCategory() method
    – Alex Dinca
    Commented Jun 23, 2014 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.