Magento Static块现在显示在CMS页面中

卢坎·阿德里安(Luican Adrian)

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

我做错了什么?谢谢 !

回声
  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();

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Magento标头中显示CMS静态块

来自分类Dev

Magento中的配置块

来自分类Dev

无法覆盖magento 1.8中的magento块

来自分类Dev

获取页面Magento的块类型

来自分类Dev

Magento-从CMS页上的页脚中删除块

来自分类Dev

Magento标头CMS块移位

来自分类Dev

Magento cms /块未正确缓存

来自分类Dev

Magento自定义扩展未在CMS页面中调用

来自分类Dev

Magento从CMS页面中删除“其他脚本”

来自分类Dev

添加新列以在magento CMS页面中安装脚本

来自分类Dev

如何获取基于magento中特定主题的cms页面列表?

来自分类Dev

如何通过Magento中的商店获取CMS页面标题?

来自分类Dev

确定Magento中CMS页面的所有商店?

来自分类Dev

Magento 2.0:在页面模板中添加静态块

来自分类Dev

Magento根据布局获取CMS页面

来自分类Dev

; [magento]“所有类别”块magento

来自分类Dev

Magento覆盖核心块

来自分类Dev

Magento覆盖块

来自分类Dev

Magento覆盖块

来自分类Dev

Magento-覆盖块

来自分类Dev

Magento 更改块标题

来自分类Dev

Magento 布局块

来自分类Dev

如何为其他语言范围复制Magento CMS页面和内容块

来自分类Dev

如何为其他语言范围复制Magento CMS页面和内容块

来自分类Dev

在Magento产品页面中查看

来自分类Dev

Magento Shopgram结帐页面

来自分类Dev

Magento产品页面变量

来自分类Dev

Magento事件以离开页面

来自分类Dev

Magento页面非常慢