magento navigation get parent category and have a constant parent category


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

usefull navigation stuff works in magento 1.5.0.1

http://www.webdesign-blog.ch/?p=17
http://www.pauldonnellydesigns.com/blog/get-parent-category-name-in-magento/


Copy this code and paste it in your HTML
  1. <?php
  2. $ella_current_category = Mage::registry('current_category');
  3. $ella_parent_id = $ella_current_category->getParentCategory();
  4. echo $ella_parent_id;
  5. ?>
  6.  
  7. Name: <?php $parentname = $this->getCurrentCategory()->getParentCategory()->getName(); echo $parentname; ?>
  8. <br />Url: <?php $parenturl = $this->getCurrentCategory()->getParentCategory()->getUrl(); echo $parenturl; ?>
  9. <br />Level: <?php $parentlevel = $this->getCurrentCategory()->getParentCategory()->getLevel(); echo $parentlevel; ?>
  10.  
  11. <?php
  12.  
  13. # Set parent Category Id
  14. $parentCategoryId = 4;
  15.  
  16. $layer = Mage::getModel('catalog/layer');
  17.  
  18. $activeCategory = $layer->getCurrentCategory();
  19. $pathIds = $activeCategory->getPathIds();
  20.  
  21. $layer->setCurrentCategory($parentCategoryId);
  22. $currentCategory = $layer->getCurrentCategory();
  23. $childCategories = $currentCategory->getChildrenCategories();
  24.  
  25. $i = '';
  26. $items = '';
  27. $list1 = '';
  28. $list2 = '';
  29.  
  30. foreach ($childCategories as $_category) {
  31.  
  32. if (in_array($_category->getId(), $pathIds)) {
  33. $items = '
  34. <li class="active">';
  35. } else {
  36. $items = '
  37. </li><li>';
  38. }
  39.  
  40. $items .= '<a href="'.$_category->getUrl().'">'.$_category->getName();'</a>';
  41. $items .= '</li>
  42.  
  43. ';
  44.  
  45. $i %2 == 0 ?
  46. $list1 .= $items:
  47. $list2 .= $items;
  48.  
  49. $i++;
  50. }
  51.  
  52. echo '
  53. <ul class="list1">'.$list1. '</ul>
  54.  
  55. ';
  56. echo '
  57. <ul class="list2">'.$list2. '</ul>
  58.  
  59. ';
  60.  
  61. ?>

URL: http://www.webdesign-blog.ch/?p=17, http://www.pauldonnellydesigns.com/blog/get-parent-category-name-in-magento/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.