4

I had a project where there was no pattern and I applied all changes of categories layout in Admin area (Catalog->Manage Categories->Custom Design tab). Now I need to have the following:
Parent category will have a grid of all subcategories with their thumbnails and titles.

Subcategories will look pretty much as default ones - Name, description and product list/grid

So I would like to do this and wonder what is the right way.

  • In the title you say you want to know it in code and in your question you say you want to know how to do it in the backend. Which one is it? :P – Rick Kuipers Jan 24 '13 at 21:19
  • Fixed) Title is the correct one. – Sergei Guk Jan 24 '13 at 21:26
6

In your catalog/category/view.phtml you can check the category level using this:

$this->getCurrentCategory()->getLevel()

If you want to decide this in the backend you could make a whole seperate template that displays all the subcategories and add the following to your custom layout updates:

<reference name="category.products">
    <action method="setTemplate"><template>catalog/category/list.phtml</template></action>
</reference>

To read out all the subcategories you can do this:

$children = explode(',', $this->getCurrentCategory()->getChildren());
$collection = Mage::getModel('catalog/category')->getCollection()
        ->addAttributeToSelect('name')
        ->addAttributeToFilter('entity_id', array(
            'in' => $children
        ))->load();

foreach ($collection as $category) {
    echo $category->getName() . '<br />';
}
1

You should be able to put an if block at the top of the catagory view template.

Something like:

<?php if ($this->IsTopCategory()) : ?>

// Insert subcategory grid logic here

<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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