gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 19:31:48 25 4
gpt4 key购买 nike

如何从主菜单中排除 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

谢谢你的帮助

最佳答案

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

首先,使用数据升级脚本创建一个代码为“use_in_navigation”的 bool 类别属性:

    $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 不同。

关于php - 如何从主菜单中排除 Magento 类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26438115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com