1

How to display category from one category? I created a new file .phtml But I do not know how to write code in phtml file. I watched Google and other issues, but have not found a friendly solution. Please, help. screenshot I have this code.screenshot

  • You might want to explain a bit more on what you're trying to accomplish. What have you tried so far? – Badger Nov 10 '15 at 20:06
  • I want to create a block on the left. In it will be displayed subcategory from one main category. He will always be displayed – Sylon Nov 11 '15 at 12:54
1

You write code in phtml the same way you write html file. If you wanna to get the category children from a specific category, you might write something like this:

$childrenCategoryCollection = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToFilter('entity_id',$parentCategoryId)
    ->addAttributeToFilter('level',$parentCategoryLevel+1);

You can do this as well

$subcats = $cat->getChildren();
$childrenCategoryCollection = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToFilter('entity_id', array(
                                    'in'=> $subcats));

At the phtml it should be this way

<?php
$subcats = $cat->getChildren();
$childrenCategoryCollection = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToFilter('entity_id', array(
                                    'in'=> $subcats));
?>
<ul>
<?php foreach ($childrenCategoryCollection as $childCat) : ?>
    <li><?php echo $childCat->getName()?></li>
<?php endforeach?>
</ul>

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.