Posted By

nico65 on 04/27/11


Tagged

category navigation links sitemap magento


Versions (?)

Magento echo all category links


 / Published in: PHP
 

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

  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. ?>

Report this snippet  

You need to login to post a comment.