Magento echo all category links


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $category = Mage::getModel('catalog/category');
  3. $tree = $category->getTreeModel();
  4. $tree->load();
  5. $ids = $tree->getCollection()->getAllIds();
  6. foreach($ids as $id)
  7. {
  8. if($id != 1)
  9. {
  10. $cat = Mage::getModel("catalog/category")->load($id);
  11. $parentcatname = strtolower(preg_replace('/ /','-',$cat->getName()));
  12. $subcats = $cat->getChildren();
  13. if ($subcats) {
  14. ?>
  15. <a href="<?php echo $this->getUrl() ?>">Home</a> |
  16. <?php
  17. foreach(explode(',',$subcats) as $subCatId)
  18. {
  19. $_category = Mage::getModel('catalog/category')->load($subCatId);
  20. if($_category->getIsActive())
  21. {
  22. $caturl = $_category->getURL();
  23. $catname = $_category->getName();
  24. echo '<a href="'.$caturl.'" title="'.$catname.'">'.$catname.'</a> |'."\n";
  25. }
  26. }
  27. ?>
  28. <?php
  29. }
  30. }
  31. }
  32. ?>

URL: http://www.magentocommerce.com/boards/viewthread/19476/P15/#t273207

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.