我是Magento的新手,想要显示Magento主页上的所有类别,而不是顶级导航菜单。在Magento主页上显示的类别
我读了很多articles在it,但没有任何帮助。请指点我正确的方向。
在此先感谢。
我是Magento的新手,想要显示Magento主页上的所有类别,而不是顶级导航菜单。在Magento主页上显示的类别
我读了很多articles在it,但没有任何帮助。请指点我正确的方向。
在此先感谢。
我问题出在哪里了。 解决方法是在此链接http://samsami2u.wordpress.com/2009/09/15/add-categories-with-images-on-homepage-magento/,我试图将此行添加到主页 {{block type =“catalog/navigation”name =“catalog.category”template =“catalog/category/list.phtml”}}从设计选项卡下布局更新xml的后端,但正确的方法是将其放置在内容选项卡中。
下面的代码做了几件事情,首先它将获得所有商店的类别 - 然后在继续之前检查它们是否处于活动状态。
<?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; ?>
感谢您的建议。但我想知道如何使用它。 – Aisha 2011-03-18 09:18:02
这种方法和这里列出的方法相结合:http://samsami2u.wordpress.com/2009/09/15/add-categories-with-images-on-homepage-magento/似乎已经解决了我的这个问题。 – Dan 2011-08-03 17:07:10