【问题标题】:How do I detect if a category has Include in Navigation Menu set to NO?如何检测一个类别是否包含在导航菜单中设置为 NO?
【发布时间】:2011-04-18 20:06:39
【问题描述】:

如何检测某个类别是否将包含在导航菜单中设置为 NO?

【问题讨论】:

    标签: magento


    【解决方案1】:

    include_in_menu 是一个属性,所以你可以使用,

    if (!$category->getIncludeInMenu()) ...
    

    【讨论】:

      【解决方案2】:

      这对我有用

       $category->load();
      //$category->getIncludeInMenu() returns 1 if set to yes, returns 0 if set to no
      if(!$category->getIncludeInMenu())
      ...
      

      【讨论】:

        【解决方案3】:

        除了加载整个对象(性能问题)之外,还有一种更好的方法来检查类别是否具有 include_in_menu 属性:

            $Category = Mage::getModel('catalog/category')
                                ->getCollection()
                                ->addFieldToFilter('parent_id', $rootCategory)
                                ->addAttributeToFilter('is_active', 1)
                                ->addAttributeToSelect(array('id', 'name', 'url','include_in_menu'))
                                ->setOrder('position','ASC');
        

        这样您将只加载构建导航所需的属性。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-09-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-02
          • 1970-01-01
          • 2018-10-09
          相关资源
          最近更新 更多