Magento-如何在phtml中过滤类别

法兰汗

我一直在maga菜单上工作。我在phtml中得到了如下集合:

<?php $_helper = Mage::helper('catalog/category') ?> <?php $_categories = $_helper->getStoreCategories() ?> <?php $currentCategory = Mage::registry('current_category') ?>

现在,我必须添加过滤器以显示特定类别。就像我有一个要显示的类别数组(1,2,3,4)因此,如何将过滤器应用于此帮助器。

任何人有任何建议请回答。

谢谢。

贾斯汀·保罗·布

第一个答案是正确的,但是效率不高,因为它消耗了不必要的数据库往返行程。@Karan的代码针对每个ID向数据库发出查询。试想一下,要过滤的类别ID的数量是否为50或以上。

我的例子是这样的:

<?php

$catIds = array(1,2,3,4);

$catCollection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('id', $catIds)->addAttributeToFilter('is_active',1);

foreach($catCollection as $category){
  echo $category->getName()." ";
}

这样会将数据库往返次数减少到仅一次。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Phtml中的Magento类别小部件

来自分类Dev

Phtml中的Magento类别小部件

来自分类Dev

如何在Magento 2中的phtml文件中覆盖

来自分类Dev

如何在magento中重写head.phtml

来自分类Dev

如何在Magento 2.0中替换phtml文件?

来自分类Dev

我如何在magento中从.phtml创建URL

来自分类Dev

如何在magento图层导航中更改类别过滤器的位置

来自分类Dev

如何在magento中显示类别和子类别

来自分类Dev

如何在magento中获取当前类别及其子类别?

来自分类Dev

如何覆盖magento中的admin phtml文件?

来自分类Dev

如何在Magento 1.9.0.1中使用2个或更多类别过滤器过滤产品

来自分类Dev

如何在Magento的多店中为网站设置类别

来自分类Dev

如何在Magento的高级搜索中包括链式选择的类别

来自分类Dev

如何在magento中从右向左更改类别块?

来自分类Dev

如何在magento中编辑类别导航设计

来自分类Dev

Magento 2-如何在header.phtml中获取购物车商品总计

来自分类Dev

如何在Magento中将模板加载到phtml文件的div中

来自分类Dev

如何在magento商店的phtml文件中制作动态产品URL密钥

来自分类Dev

如何在Magento PHTML页面中使用简码

来自分类Dev

如何从Magento中的phtml获取xml中的block标签?

来自分类Dev

Magento:如何在magento菜单中两行显示类别名称?

来自分类Dev

如何在magento的自定义脚本中获取产品的多个类别和子类别

来自分类Dev

在Magento中按多个类别过滤产品

来自分类Dev

Magento中的左列phtml文件

来自分类Dev

Magento 2 phtml文件中的条件语句

来自分类Dev

Magento中的扩展类别级别

来自分类Dev

在magento中获取当前类别

来自分类Dev

如何在magento的类别页面上检索所选的订单属性?

来自分类Dev

如何在magento的类别页面上检索所选的订单属性?

Related 相关文章

  1. 1

    Phtml中的Magento类别小部件

  2. 2

    Phtml中的Magento类别小部件

  3. 3

    如何在Magento 2中的phtml文件中覆盖

  4. 4

    如何在magento中重写head.phtml

  5. 5

    如何在Magento 2.0中替换phtml文件?

  6. 6

    我如何在magento中从.phtml创建URL

  7. 7

    如何在magento图层导航中更改类别过滤器的位置

  8. 8

    如何在magento中显示类别和子类别

  9. 9

    如何在magento中获取当前类别及其子类别?

  10. 10

    如何覆盖magento中的admin phtml文件?

  11. 11

    如何在Magento 1.9.0.1中使用2个或更多类别过滤器过滤产品

  12. 12

    如何在Magento的多店中为网站设置类别

  13. 13

    如何在Magento的高级搜索中包括链式选择的类别

  14. 14

    如何在magento中从右向左更改类别块?

  15. 15

    如何在magento中编辑类别导航设计

  16. 16

    Magento 2-如何在header.phtml中获取购物车商品总计

  17. 17

    如何在Magento中将模板加载到phtml文件的div中

  18. 18

    如何在magento商店的phtml文件中制作动态产品URL密钥

  19. 19

    如何在Magento PHTML页面中使用简码

  20. 20

    如何从Magento中的phtml获取xml中的block标签?

  21. 21

    Magento:如何在magento菜单中两行显示类别名称?

  22. 22

    如何在magento的自定义脚本中获取产品的多个类别和子类别

  23. 23

    在Magento中按多个类别过滤产品

  24. 24

    Magento中的左列phtml文件

  25. 25

    Magento 2 phtml文件中的条件语句

  26. 26

    Magento中的扩展类别级别

  27. 27

    在magento中获取当前类别

  28. 28

    如何在magento的类别页面上检索所选的订单属性?

  29. 29

    如何在magento的类别页面上检索所选的订单属性?

热门标签

归档