!我正在尝试在cms页面上显示类别。我已经尝试了网络上的所有解决方案,但没有一个对我有用。我尝试的最后一个是这个。
1.我已将此代码添加到我的cms页面的内容标签中:{{block type =“ catalog / navigation” template =“ catalog / category / list.phtml”}}
2.我创建了list.phtml并将文件放在app / design / theme-name / template / catalog / category上。
这是我文件的代码
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $open = $this->isCategoryActive($_category); ?>
<?php
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
if ($immagine = $this->getCurrentCategory()->getImageUrl()):
?>
<div class="catalog-image">
<div>
<a href="<?php echo $this->getCategoryUrl($_category)?>">
<img src="<?php echo $immagine ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="313" height="151" />
</a>
</div>
<div class="left"><h2><a href="<?php echo $this->getCategoryUrl($_category)?>"><?php echo $_category->getName()?></a></h2></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
我做错了什么?谢谢 !
{{block type =“ core / template” template =“ page / categories-list.phtml”}}
路径:app / design /主题名称/template/page/categories-list.phtml
在此文件中,编写以下代码以获取所有类别的集合:
<?php
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
?>
如果只需要某些类别的父母,请使用以下代码:
<?php
$parent_category_id = 5; // this is ID of parent category
$categories = Mage::getModel('catalog/category')->getCategories($parent_category_id);
?>
要在屏幕上显示类别,请使用循环,如下所示:
<?php foreach ($categories as $category): ?>
<p><?php echo $category->getImageUrl(); ?></p>
<p><?php echo $category->getName(); ?></p>
<?php endforeach; ?>
如果使用父类别的类别来显示图像,请使用以下代码:
Mage::getModel('catalog/category')->load($category->getId())->getImageUrl();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句