tags:

views:

95

answers:

2

HI, Now i get all categorys and subcategory. How get only subcategory?

<?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
A: 

Hi, $this->getStoreCategories() returns a Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection, which has an addPathFilter() method. Look at this method's prototype : it has one argument : $regexp If you know about regular expressions, you can build a regexp which filters your categories by path. Try first to print the categories paths (by doing echo $_category->getPathInStore()), then find a regexp which filters category paths the way you want.

greg0ire
Sorry, I did not understand, can you detail.My second try:get category id with: $_category->getId(), but how bet subcategory?
lolalola
I edited my post, is it clearer? Edit your post and show us your category paths, so that we can help you.
greg0ire
+2  A: 

This will give you "mother" categories + 1st level children categories.

<ul>
 <?php foreach ($this->getStoreCategories() as $_category): ?>
 <li>
  <strong><?php echo $_category->getName(); ?></strong>
   <?php $_children = $_category->getChildren(); ?>
   <?php if($_children->count()) : ?>
  <ul>
     <?php foreach($_children as $_child) : ?>
   <li><?php echo $_child->getName(); ?></li>
     <?php endforeach; ?>
  </ul>
   <?php endif; ?>
 </li>
 <?php endforeach ?>
</ul>

If you only want to display 1st level subcategories just comment/remove the first

<strong><?php echo $_category->getName(); ?></strong>
vrnet