所有类别页面的自定义布局 magento

custom layout for all categories page magento

我想在产品类别页面上显示子类别图片。 1. 我用自定义代码创建了 category_listing.phtml 来显示子类别 2.创建了一个静态块

{{block type="core/template" template="catalog/navigation/category_listing.phtml"}}

关于类别显示设置,我已 select 编辑 'static block and products'。 说我有三类 类别 1 类别 2 类别 3

如果我 select 一个类别的静态块仅是完美的,但如果我在多个类别中调用静态块,它会显示错误的子类别,除非我每次都删除缓存。 有没有我遗漏的步骤,考虑到我是 magento 的新手,请回复

谢谢

打开文件:app/design/frontend/yourtheme/default/template/catalog/category/view.phtml 并添加以下代码:

<div class="category-grid-new">
    <?php $_columnCount = 4;?>
    <?php if ($i++%$_columnCount==0): ?>
        <ul class="sub-category">
        <?php endif; ?>
            <?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
                <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0):?> last<?php endif; ?>">
                    <a href="<?php echo $_subcat->getUrl() ?>">
                        <div class="category-img"><img src="<?php echo $_category->getImageUrl() ?>" alt="" width="100px" height="100px"/></div>
                        <div class="category-name"><?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName()) ?></div>
                    </a>
                </li>
            <?php endforeach; ?>
    <?php if ($i%$_columnCount==0): ?>
        </ul>
    <?php endif; ?> 
</div>

1.对于 Magento 中的自定义类别菜单导航

布局
打开 app/design/frontend/base/default/layout/page.xml 或您的主题的等效项。 将以下代码放在默认标签下:

<reference name="right">
     <block type="core/template" name="catalog.sidenav" template="page/custom.phtml" before="cart_sidebar"/>
</reference>

使用以下内容创建 app/design/frontend/base/default/template/page/custom.phtml

<ul>
    <?php
        $obj = new Mage_Catalog_Block_Navigation();
        $storeCategories = $obj->getStoreCategories();
        Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
        foreach ($storeCategories as $_category):
    ?>
            <li>
                <strong><?php echo $_category->getName(); ?></strong>
                <?php $categoryChildren = $_category->getChildren(); ?>
                <?php if($categoryChildren->count()) : ?>
                    <ul>

                        <?php foreach($categoryChildren as $_categoryChild) : ?>
                            <?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
                            <?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
                            <li>
                                <?php
                                    $currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
                                    echo '&emsp;' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' .  $_categoryChild->getName() . '(' . $_categoryChildModel->getProductCollection()->count() . ')</a>';
                                ?>
                            </li>
                            <?php if($categoryGrandchildren->count()) : ?>
                                <?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?>
                                    <?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?>
                                    <li>
                                        <?php
                                            $currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
                                            echo '&emsp;&emsp;' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' .  $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
                                        ?>
                                    </li>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach ?>
</ul>

您还可以通过编写布局更新代码或通过管理员将此模板插入任何其他页面,方法是将此行作为 CMS 页面的内容插入:

{{block type="core/template" template="page/custom.phtml"}}

2.To 左侧边栏添加分类导航:

在您的主题中创建新文件 "category_listing.phtml" -

app/design/frontend/{your_namespace}/{your_module}/template/catalog/navigation/category_listing.phtml

将以下代码放入其中:

<div class="block block-category">
   <div class="inside-box">
      <div class="block-title block-category-title">
         <h2><?php echo $this->__('Categories') ?></h2>
      </div>
      <div class="block-category-navigation">
         <ul id="category-nav">
            <?php foreach ($this->getStoreCategories() as $_category): ?>  
            <?php if($_category->name!=""):  ?>    
            <li><?php echo $this->drawItem($_category) ?></li>
            <?php endif?>  
            <?php endforeach ?>    
         </ul>
      </div>
   </div>
</div>

然后在位于主题文件夹中的 catalog.xml 文件中调用它 -

app/design/frontend/{your_namespace}/{your_module}/layout/catalog.xml

代码:

<reference name="left">
   <-- this is new block added by us -->
   <block type="catalog/navigation" name="catalog.categorymenu" after="top.search" template="catalog/navigation/category_listing.phtml"/>

   <block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
   ...
   ...
   ...
</reference>