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

时间:2014-10-18 09:17:32

标签: php css magento magento-1.7

如何从主菜单中排除Magento类别,并将其保留在侧栏中。我在Google上搜索时尝试了这两个代码,将默认的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

感谢您的帮助

3 个答案:

答案 0 :(得分:0)

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

首先,使用数据升级脚本创建一个包含代码'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”为假的任何子项的渲染:

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 :(得分:0)

简单地说 1-导航至目录 - &gt;管理类别
2-从主菜单中选择要排除的类别 3-设置包含在导航菜单选项(位于页面底部)

答案 2 :(得分:-1)

根据您的主题,您可以使用原型或jQuery删除UL标记的特定子项。例如,如果要删除第二个类别,则可以使用此类代码删除导航UL的第二个LI

相关问题