Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Magento的主页上显示类别_Magento_Categories - Fatal编程技术网

在Magento的主页上显示类别

在Magento的主页上显示类别,magento,categories,Magento,Categories,我是Magento的新手,希望在Magento主页上显示所有类别,而不是顶部导航菜单 我在网上读了很多书,但没有任何帮助。请给我指一下正确的方向 提前感谢。下面的代码做了几件事,首先它将获取商店的所有类别,然后在继续之前检查它们是否处于活动状态 代码礼貌: $\u main\u categories数组为空 这可能是因为引用此phtml文件时使用了错误的类型属性。你应该使用 我找到了问题所在。 解决方案是在这个链接,我试图添加这一行 {{block type=“catalog/nav

我是Magento的新手,希望在Magento主页上显示所有类别,而不是顶部导航菜单

我在网上读了很多书,但没有任何帮助。请给我指一下正确的方向


提前感谢。

下面的代码做了几件事,首先它将获取商店的所有类别,然后在继续之前检查它们是否处于活动状态

代码礼貌:


    $\u main\u categories数组为空

    这可能是因为引用此phtml文件时使用了错误的类型属性。你应该使用


我找到了问题所在。 解决方案是在这个链接,我试图添加这一行
{{block type=“catalog/navigation”name=“catalog.category”template=“catalog/category/list.phtml”}从后端在“设计”选项卡下的布局更新xml中转到主页,但正确的方法是将其放在“内容”选项卡中。

Thanx for ur advice。但我想知道如何使用它。这种方法和这里概述的方法的结合似乎为我解决了这个问题。
   <?php
     /* Get the categories that are active for the store */
      $_main_categories=$this->getStoreCategories();
      /* Get the current category the user is in */
      $_current_category=$this->getCurrentCategory();
      /* Get the current category path */
      $_categorypath = $this->getCurrentCategoryPath();
      ?>
      <ul>
      <?php
      if ($_main_categories):
          /* This bit cycles through the categories - setting the next one to current */
          foreach ($_main_categories as $_main_category):
            if($_main_category->getIsActive()):                             
          $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId());
                 $layer = Mage::getSingleton('catalog/layer');
                 $layer->setCurrentCategory($cur_category);     
      /* Write the main categories */           
      ?>               
      <li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li>   
      <?php
      /* Check the category variable loop against the current category path if it is - print sub categories */
      if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?>
      <?php $_maincategorylisting=$this->getCurrentCategory()?>                       
      <?php $_categories=$this->getCurrentChildCategories()?>
      <?php if($_categories->count()):?>
      <ul>
      <? foreach ($_categories as $_category):?>                   
         <? if($_category->getIsActive()):                   
            $cur_subcategory=Mage::getModel('catalog/category')->load($_category->getId());
                 $layer = Mage::getSingleton('catalog/layer');
                 $layer->setCurrentCategory($cur_subcategory); 
      ?>                         
      <li><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></li>
          <? endif;?>
      <?endforeach?>
      </ul>           
      <?php /* This resets the category back to the original pages category
      ****     If this is not done, subsequent calls on the same page will use the last category
      ****    in the foreach loop
      */   ?>
      <?php $layer->setCurrentCategory($_current_category);  ?>
      <?endif;?>   
      <?endif;?>                                   
      <?php         
      endif;
      endforeach;
      else:
      ?>
      <p>$_main_categories array was empty.</p>
      <p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p>
      <?php endif; ?>