0

嗨!我正在尝试在 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; ?>

我做错了什么?谢谢 !

4

2 回答 2

0
  1. 在具有名称导航的目录下创建一个文件夹,并将您的 list.phtml 文件放在那里它将起作用。

    {{block type="core/template" template="catalog/navigation/list.phtml" category_id="507" }}

  2. 类别显示模式应该在显示设置中的静态块中。

于 2015-11-26T06:21:56.730 回答
0
  1. 在您的 cms 页面的内容选项卡中添加此代码:

{{block type="core/template" template="page/categories-list.phtml"}}

  1. 在主题中创建一个文件,例如“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();

于 2015-11-26T07:02:18.873 回答