【问题标题】:magento get category info in the top of the 2 columns templatemagento 在 2 列模板的顶部获取类别信息
【发布时间】:2014-05-05 19:29:00
【问题描述】:

在我的 magento 商店中,我有一个基本类别,例如:http://demo.magentocommerce.com/electronics/cellphones。我正在使用模板 2columns-left.phtml。

现在我想要(全宽,在菜单和产品列表之间)类别信息(图片和描述),宽度为 100%。

在我的模板 2columns-left.phtml 中,我创建了这一行:

<?php echo $this->getChildHtml('category_info') ?>

但是我怎样才能在这里获得类别描述和照片呢?

我想我需要在我的类别中进行自定义布局更新,例如:

<block type="??" name="categpry_page_info" as="topCategoriInfo"
                   template="page/category_info.phtml"/>

但是我该怎么做呢?以及如何在我的 category_info.phtml 模板中接收类别描述和照片?

或者,也许还有其他方法可以在我的类别页面中获取此信息?

【问题讨论】:

    标签: xml magento templates categories


    【解决方案1】:

    我已经把 magento 块模板类 Mage_Catalog_Category_View.

    app/design/frontend/yourpackage/yourtemplate/layout/local.xml和下创建local.xml

    <?xml version="1.0"?>
    <layout version="0.1.0">
    <catalog_category_default>
          <reference name="content">
            <block type="catalog/category_view" name="categpry_page_info" as="topCategoriInfo"
                               template="page/category_info.phtml" before="category.products"/>
        </reference>
         </catalog_category_default>
         <catalog_category_layered>
           <reference name="content">
            <block type="core/template" name="categpry_page_info" as="topCategoriInfo"
                               template="page/category_info.phtml" before="category.products"/>
         </reference>
         </catalog_category_layered>
         </layout>
    

    category_info.phtml的代码是

      <?php
        $_helper    = $this->helper('catalog/output');
        $_category  = $this->getCurrentCategory();
        $_imgHtml   = '';
        if ($_imgUrl = $_category->getImageUrl()) {
            $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';
            $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
        }
    ?>
    <div class="page-title category-title">
        <?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
            <a href="<?php echo $this->getRssLink() ?>" class="link-rss"><?php echo $this->__('Subscribe to RSS Feed') ?></a>
        <?php endif; ?>
        <h1><?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></h1>
    </div>
    
    <?php if($_imgUrl): ?>
        <?php echo $_imgHtml ?>
    <?php endif; ?>
    
    <?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
        <div class="category-description std">
            <?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
        </div>
        <?php endif; ?
    

    获取分类图片和描述,需要上传分类图片和描述

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      相关资源
      最近更新 更多