我有一个Magento商店,想要在首页上显示带有描述和图像的顶级类别。有谁知道我怎么解决这个问题?
我有这个来显示顶级类别:
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
但我无法让它显示描述和图像。 希望有人能帮助我。
此致 罗伯特
答案 0 :(得分:0)
您可以使用模块实现此目的:
注意:在此方法中,您可以显示要显示的块(主页,页脚,侧栏,其他页面)。
<强>步骤:强> 这里, [命名空间] = Codilar &amp; [模块名] = <强>分类强>
创建xml :app / etc / modules / Codilar_Category.xml
<?xml version="1.0"?>
<config>
<modules>
<Codilar_Category>
<active>true</active>
<codePool>local</codePool>
</Codilar_Category>
</modules>
</config>
创建config.xml :app / code / local / Codilar / Category / etc / config.xml
<?xml version="1.0"?>
<config>
<modules>
<Codilar_Category>
<version>1.0</version>
</Codilar_Category>
</modules>
<global>
<blocks>
<codilar_category>
<class>Codilar_Category_Block</class>
</codilar_category>
</blocks>
<models>
<codilar_category>
<class>Codilar_Category_Model</class>
</codilar_category>
</models>
</global>
</config>
创建模型:app / code / local / Codilar / Category / Model / Category.php
<?php
class Codilar_Category_Model_Category extends Mage_Core_Model_Abstract {
public function getActiveCategory() {
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
return $categories;
}
}
创建阻止:app / code / local / Codilar / Category / Block / Category.php
<?php
class Codilar_Category_Block_Category extends Mage_Core_Block_Template {
public function getActiveCategory() {
$arr_categories = array();
$categories = Mage::getModel("codilar_category/category")->getActiveCategory();
foreach ($categories as $category) {
$arr_categories[] = array(
'id' => $category->getId(),
'name' => $category->getName(),
'url' => $category->getProductUrl(),
'image' => $category->getThumbnail(),
'desc' => $category->getDescription(),
);
}
return $arr_categories;
}
}
创建模板文件: 应用程序/设计/前端/默认/默认/模板/ codilar /类别/ category.phtml
<?php
$categories = $this->getActiveCategory();
?>
<div id="category_list">
<h1>All Category</h1>
<?php if (is_array($categories) && count($categories)) { ?>
<?php foreach($categories as $category) { ?>
<div>
<a href="<?php echo $category['url'] ?>"><?php echo $category['name'] ?></a>
</div>
<div>
<img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'. $category['image']; ?>" alt="<?php echo $category['image'] ?>" height="100" width="100">
</div>
<div>
<p><?php echo $category['desc'] ?></p>
</div>
<?php } ?>
<?php } ?>
</div>
要使用布局更新文件插入类别自定义块,可以使用以下代码。
<block type="codilar_category/category" name="codilar_category_category" template="codilar/category/category.phtml"></block>
另一方面,如果您想使用CMS页面显示类别自定义块,请输入以下代码。
{{block type="codilar_category/category" name="codilar_category_category" template="codilar/category/category.phtml"}}
答案 1 :(得分:0)
我正在努力展示来自每个顶级类别的2个产品,其中包含以下代码:
WITH
MEMBER [Measures].[Today1] AS
VBAMDX.NOW()
MEMBER [Measures].[Today2] AS
VBAMDX.NOW()-1
MEMBER [Measures].[Today3] AS
VBAMDX.FORMAT(VBAMDX.NOW()-1,"yyyy-MM-dd")
...
但我还需要显示描述和价格,但不知何故getPriceHtml似乎不起作用:(