Magento静态块现在显示在CMS页面中



Hy!我正在尝试在cms页面上显示类别。我在网上试过所有的解决方案,但没有一个对我有效。我最后试过的是这个。

1.我在cms页面的内容选项卡中添加了以下代码:{{block type="catalog/navigation"template="catalog/category/list.phtml"}}

2.我已经创建了list.phtml,并将文件放在app/design/theme-name/template/controlog/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; ?>

我做错了什么?谢谢

  1. 在cms页面的内容选项卡中添加以下代码:

{{block type="核心/模板"template="页面/类别列表.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();

  1. 在带有名称导航的目录下创建一个文件夹,并将您的list.phtml文件放在那里,它就可以工作了。

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

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

最新更新