如何从主菜单中排除Magento类别


How Do I exclude a Magento category from the main menu

如何从主菜单中排除Magento类别,并在侧栏中保持它。我已经尝试了这两个代码,我在谷歌上搜索时通过将默认的magento替换为这些,但它不起作用

这是代码

 <?php $_menu = "" ?>
  <?php if($_menu): ?>
  <div class="nav-container">
  <ul id="nav">
  <?php foreach ($this->getStoreCategories() as $_category): ?>
  <?php if(stristr('71,70,69', $_category->getId()) === FALSE) : ?> 
  <?php echo $this->drawItem($_category) ?>
  <?php endif ?>
   <?php endforeach ?>
   <?php // echo $_menu ?>
    </ul>
   </div>
  <?php endif  ?>

这是第二段代码。我也是从谷歌上得到的。

  <?php $_menu = ''?>
  <?php foreach ($this->getStoreCategories() as $_category): ?>
  <?php $_menu .= $this->drawItem($_category) ?>
 <?php endforeach ?>
 <?php if ($_menu): ?>
   <div class="nav-container">
      <ul id="nav">
    <?php foreach ($this->getStoreCategories() as $_category): ?>
       <?php if (!in_array($_category->getId(), array(12,34,56))) : ?> <?php echo $this-     >drawItem($_category) ?>
      <?php endif; ?>
     <?php endforeach ?>
    </ul>
  </div>
  <?php endif; */ ?>

它们似乎都不起作用。我正在使用magento 1。7.1

感谢您的帮助

从顶部导航菜单中排除一个类别,但在左侧菜单中保留该类别。菜单项是否应显示在顶部导航菜单中可以在管理员中进行控制。您必须执行以下步骤:

首先,使用数据升级脚本创建一个布尔类别属性,代码为"use_in_navigation":

    $installer = $this;
    $installer->startSetup();
    $installer->addAttribute('catalog_category', 'use_in_navigation', array(
    'type'          => 'int',
    'input'         => 'select',
    'label'         => 'Use in navigation',
    'required'      => false,
    'note'          => '',
    'user_defined'  => '1',
    'source'        => 'eav/entity_attribute_source_boolean',
    'default'       => false));
    $entityTypeId     = $installer->getEntityTypeId('catalog_category');
    $attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
    $installer->addAttributeToGroup(
        $entityTypeId,
        $attributeSetId,
        'General Information',
        'use_in_navigation',
        100);
    $installer->endSetup();

其次,覆盖"Mage_Page_Block_Html_Topmenu"中的"_getHtml",并跳过"use_in_navigation"为false的任何子项的呈现:

protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass){
....
    foreach ($children as $child) {
        if(!$child->getUseInNavigation()){
            continue;
        }
        ....
    }
}

应该有这样的方法。

注:函数名称取自Magento CE 1.8。它们可能与Magento CE 1.7不同。

简单地
1-导航到目录->管理类别
2-选择要从主菜单中排除的类别
3-将Include in Navigation Menu选项设置为No(在页面底部)

根据您的主题,您可以使用prototype或jQuery来删除UL标签的特定子级。例如,如果你想删除第二个类别,那么你可以使用这样的代码来删除导航UL 的第二个LI