Cómo cambiar la plantilla de página de categoría dependiendo del nivel de la categoría en código?
Pregunta
Yo tenía un proyecto en el que no hubo un patrón y aplica todos los cambios de categorías de diseño en el área de administración (pestaña Catalog->Manage Categories->Custom Design
). Ahora tengo que tener la siguiente:
categoría padre tendrá una cuadrícula de todas las subcategorías con sus miniaturas y títulos.
subcategorías se verá más o menos como falta de pago - nombre, descripción y lista de producto / sistema
Así que me gustaría hacer esto y preguntarse qué es la manera correcta.
Solución
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 />';
}
Otros consejos
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; ?>