开发者

magento show subcategory

开发者 https://www.devze.com 2023-01-03 14:41 出处:网络
HI, Now i get all categorys and subcategory. How g开发者_高级运维et only subcategory? <?php foreach ($this->getStoreCategories() as $_category): ?>

HI, Now i get all categorys and subcategory. How g开发者_高级运维et only subcategory?

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


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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消