如何创建显示所有类别的静态块


11

我想创建一个静态块,显示所有类别并将其显示在列表中。我不需要图像,也不需要子类别。

然后,我想将此块添加到我的主页。

Answers:


6

在其中创建一个.phtml文件app/design/frontend/your_theme/default/template/catalog,让其命名为homecategories.phtml并将此代码粘贴到其中

  <!-- Categories display start -->
        <div class="home_categories">
              <ul>
                   <?php $helper = $this->helper('catalog/category') ?>
                 <?php foreach ($helper->getStoreCategories() as $_category): ?>
                 <li>
                     <a href="<?php echo Mage::getModel('catalog/category')->setData($_category->getData())->getUrl(); ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a>
                 </li>
                 <?php endforeach ?>
              </ul>

        </div>
         <?php echo $this->getChildHtml() ?>

        <!-- Categories display end -->

现在创建一个静态块,将其命名为homecategoriesid,home_categories然后将代码放入该块的内容中,以这种方式{{block type="core/template" template="catalog/homecategories.phtml"}}调用此静态块cms.xml

<block type="cms/block" name="homecategories">
   <action method="setBlockId"><block_id>home_categories</block_id></action>
</block>

我注意到您还可以添加以下内容:{{block type =“ core / template” template =“ catalog / homecategories.phtml”}}到任何静态块中,以在任何地方显示主要类别。但是,这不显示子类别,我也需要。
Webninja

1

从admin创建一个静态块然后

app/design/frontend/yourpackage/yourtemplate/layout在下面的代码之下和之后创建一个local.xml文件

  <?xml version="1.0"?>
        <layout version="0.1.0">
        <catalog_category_layered>

                <reference name="category.products">
                    <block type="cms/block" name="cat_static_block" >
                        <!--
                            The content of this block is taken from the database by its block_id.
                            You can manage it in admin CMS -> Static Blocks
                        -->
                        <action method="setBlockId"><block_id>yourblock_id</block_id></action>
                    </block>
                </reference>
        </catalog_category_layered>
           <catalog_category_default>

                <reference name="category.products">
                    <block type="cms/block" name="cat_static_block" >
                        <!--
                            The content of this block is taken from the database by its block_id.
                            You can manage it in admin CMS -> Static Blocks
                        -->
                        <action method="setBlockId"><block_id>yourblock_id</block_id></action>
                    </block>
                </reference>
        </catalog_category_default>
    </layout>

然后转到app/design/frontend/yourpackage/yourtemplate/template/catalog/category/view.phtml 添加代码<?php echo $this->getChildHtml('cat_static_block');?>


抱歉,我在哪里创建此local.xml?以及我在admin中将静态块内容放入什么?
亚当·艾伦

是的,您需要admih的cms静态块...
阿米特·贝拉

我已经创建了一个ID为all_cat_home的静态块,但是我需要在管理页面上提交的内容中放入一些内容。我在那里写什么?
亚当·艾伦
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.