3

I need to implement category navigation left sidebar and show only current category and children. I add left_nav.phtml.

<?php
$object = new Mage_Catalog_Block_Navigation();
$actualCategoryId = $object->getCurrentCategory()->getId();
$actualCategory = Mage::getModel('catalog/category')->load($actualCategoryId);
$subCategories = explode(',', $actualCategory->getChildren());

?>
<div class="vertnav-container">
    <h1><?php echo $actualCategory->getName(); ?></h1>
    <ul>
    <?php
    foreach ( $subCategories as $subCategoryId ) :
        $category = Mage::getModel('catalog/category')->load($subCategoryId);
        if ( $category->getIsActive() ): ?>
            <li><?php echo '<a href="'.$category->getURL().'">'.$category->getName().'</a> '; ?></li>
        <?php endif; ?>
        <?php endforeach; ?>
        </ul>
</div>

But problem is when I clicked on subcategory, it's show only name, cause subcategory don't has children. But I need to show Parent and children, when I click on it. Thanks.

ANSWER:

if ($actualCategory->getData('level') != 2) {
    $actualCategory = $actualCategory->getParentCategory();
}
$subCategories = explode(',', $actualCategory->getChildren());

I made it like this, but I open for another answers ;)

  • 2
    Please write your solution as an answer. – Marius Feb 3 '14 at 13:23
  • 1
    I don't have enough reputation :( – Stopper Feb 3 '14 at 15:04
  • Do you have enough now, or how many do you need? – Flyingmana Feb 18 '14 at 22:49
1

I'm sorry but to have an answer here (added by Stopper himself)

if ($actualCategory->getData('level') != 2) {
    $actualCategory = $actualCategory->getParentCategory();
}
$subCategories = explode(',', $actualCategory->getChildren());

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.