【问题标题】:How to show categories which are not included in navigation menu in Magento如何显示 Magento 导航菜单中未包含的类别
【发布时间】:2014-09-26 14:34:14
【问题描述】:

如何在 Magento 中显示未包含在导航菜单中的类别?

<?php $_subcategories = $_category->getChildrenCategories(); ?>
    <li>
      <a <?php if (count($_subcategories) > 0){ ?>
      href='#' 
      <?php }else {  ?>
      href="<?php echo $_helper->getCategoryUrl($_category)?>"    

      <?php }?>

     <?php echo $_category->getName() ?></a>

    </li>

<?php } ?>

【问题讨论】:

    标签: php mysql magento filter categories


    【解决方案1】:
    $collection = Mage::getResourceModel('catalog/category_collection')
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('is_active', 1) //only active categories
        ->addAttributeToFilter('include_in_menu', 0)
        ->addAttributeToSort('position');//sort by position
    
    foreach ($collection as $category) {
    //do something with $category
    }
    

    【讨论】:

    • 让我添加一个过滤器以获取特定父类别中的类别。 -&gt;addAttributeToFilter('parent_id',array('eq' =&gt; $parentId));
    【解决方案2】:

    在类别集合中,您必须检查它是否包含在导航菜单中

    if (!$_category->getIncludeInMenu()) {
        // your code here
    }
    

    这是让它工作的代码 -

    foreach($_subcategories->getData() as $category) {
        $subcatid = $category['entity_id'];
        $_cat = Mage::getModel('catalog/category')->load($subcatid);
        if (!$_cat->getIncludeInMenu()) {
            echo $_cat->getName();
        }
    }
    

    【讨论】:

    • 我得到:调用未定义的方法 Varien_Data_Tree_Node_Collection::getData()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多