【问题标题】:How Do I exclude a Magento category from the main menu如何从主菜单中排除 Magento 类别
【发布时间】:2014-12-13 19:26:34
【问题描述】:

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

这里是代码

 <?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

感谢您的帮助

【问题讨论】:

    标签: php css magento magento-1.7


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      首先,使用数据升级脚本创建一个带有代码“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 不同。

      【讨论】:

        【解决方案3】:

        只是
        1- 导航到目录->管理类别
        2- 从主菜单中选择要排除的类别
        3-将包含在导航菜单中选项设置为(在页面底部)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-02-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多