Posted By

vbth on 07/11/13


Tagged


Versions (?)

Category and Childcategory snippet


 / Published in: PHP
 

Comment

  1. <ul>
  2. <?php $parentCategoryId = 3;
  3. foreach (Mage::getModel('catalog/category')->load($parentCategoryId)->getChildrenCategories() as $_category): ?>
  4. <li class="<?php echo $_category->getName(); ?>">
  5. <a href="<?php echo $_category->getUrl(); ?>"><?php echo $_category->getName(); ?></a>
  6. <?php if ($currentCategory & $currentCategory->getId() == $_category->getId()): ?>
  7. <?php $parentCategory = $currentCategory ?>
  8. <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
  9. <?php $_subcategories = $_category->getChildrenCategories() ?>
  10. <?php if (count($_subcategories) > 0): ?>
  11. <ul>
  12. <?php foreach($_subcategories as $_subcategory): ?>
  13. <li>
  14. <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
  15. <?php echo $_subcategory->getName() ?>
  16. </a>
  17. </li>
  18. <?php endforeach; ?>
  19. </ul>
  20. <?php endif; ?>
  21. <?php endif; ?>
  22. </li>
  23. <?php endforeach

Report this snippet  

You need to login to post a comment.