Php magento-静态块中的类别名称和图像?
如何通过magento后端引用magento中静态块中的类别名称和图像?我正在运行1.7。我不知道如何从静态块中轻松引用这些值 相反,我建议您创建并使用一个小部件(在我看来,这是Magento最未充分利用的功能之一),它将提供一种更干净、更可扩展的方式来实现这一点,尽管它确实需要更多的前期工作:) 有关Magento小部件的完整(简化)示例,请参见下面的代码,该小部件完全按照静态块中的要求执行: app/etc/modules/YourCompany\u Categorywidget.xmlPhp magento-静态块中的类别名称和图像?,php,magento,Php,Magento,如何通过magento后端引用magento中静态块中的类别名称和图像?我正在运行1.7。我不知道如何从静态块中轻松引用这些值 相反,我建议您创建并使用一个小部件(在我看来,这是Magento最未充分利用的功能之一),它将提供一种更干净、更可扩展的方式来实现这一点,尽管它确实需要更多的前期工作:) 有关Magento小部件的完整(简化)示例,请参见下面的代码,该小部件完全按照静态块中的要求执行: app/etc/modules/YourCompany\u Categorywidget.xml &
<config>
<modules>
<MyCompany_Categorywidget>
<active>true</active>
<codePool>community</codePool>
</MyCompany_Categorywidget>
</modules>
</config>
<?xml version="1.0"?>
<widgets>
<category_widget type="categorywidget/catalog_category_widget_info" translate="name description" module="categorywidget">
<name>Category Info Block</name>
<description>Category Info Block showing name, image etc</description>
<parameters>
<block_title translate="label">
<required>1</required>
<visible>1</visible>
<label>Block Title</label>
<type>text</type>
</block_title>
<template>
<required>1</required>
<visible>1</visible>
<label>Template</label>
<type>select</type>
<value>categorywidget/info.phtml</value>
<values>
<default translate="label">
<value>categorywidget/info.phtml</value>
<label>Category Widget Info Block - Default Template</label>
</default>
<!-- Add different temmplates here for different block positions -->
</values>
</template>
<category translate="label">
<visible>1</visible>
<required>1</required>
<label>Category</label>
<type>label</type>
<helper_block>
<type>adminhtml/catalog_category_widget_chooser</type>
<data>
<button translate="open">
<open>Select Category...</open>
</button>
</data>
</helper_block>
<sort_order>10</sort_order>
</category>
</parameters>
</category_widget>
</widgets>
真的
社区
app/code/community/MyCompany/Categorywidget/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<MyCompany_Categorywidget>
<version>1.0.0</version>
</MyCompany_Categorywidget>
</modules>
<global>
<blocks>
<categorywidget>
<class>MyCompany_Categorywidget_Block</class>
</categorywidget>
</blocks>
<helpers>
<categorywidget>
<class>MyCompany_Categorywidget_Helper</class>
</categorywidget>
</helpers>
</global>
</config>
1.0.0
MyCompany\u类别Widget\u区块
MyCompany\u类别Widget\u助手
app/code/community/MyCompany/Categorywidget/etc/widget.xml
<config>
<modules>
<MyCompany_Categorywidget>
<active>true</active>
<codePool>community</codePool>
</MyCompany_Categorywidget>
</modules>
</config>
<?xml version="1.0"?>
<widgets>
<category_widget type="categorywidget/catalog_category_widget_info" translate="name description" module="categorywidget">
<name>Category Info Block</name>
<description>Category Info Block showing name, image etc</description>
<parameters>
<block_title translate="label">
<required>1</required>
<visible>1</visible>
<label>Block Title</label>
<type>text</type>
</block_title>
<template>
<required>1</required>
<visible>1</visible>
<label>Template</label>
<type>select</type>
<value>categorywidget/info.phtml</value>
<values>
<default translate="label">
<value>categorywidget/info.phtml</value>
<label>Category Widget Info Block - Default Template</label>
</default>
<!-- Add different temmplates here for different block positions -->
</values>
</template>
<category translate="label">
<visible>1</visible>
<required>1</required>
<label>Category</label>
<type>label</type>
<helper_block>
<type>adminhtml/catalog_category_widget_chooser</type>
<data>
<button translate="open">
<open>Select Category...</open>
</button>
</data>
</helper_block>
<sort_order>10</sort_order>
</category>
</parameters>
</category_widget>
</widgets>
类别信息块
显示名称、图像等的类别信息块
1.
1.
标题栏
文本
1.
1.
模板
选择
categorywidget/info.phtml
categorywidget/info.phtml
类别小部件信息块-默认模板
1.
1.
类别
标签
adminhtml/目录\类别\小部件\选择器
选择类别。。。
10
app/code/community/MyCompany/Categorywidget/Helper/Data.php
<?php
class MyCompany_Categorywidget_Helper_Data extends Mage_Core_Helper_Abstract
{}
“alt=”“/>
我希望图像也链接到该类别,因此我添加了
app/code/community/MyCompany/Categorywidget/Block/Catalog/Category/Info.php
<?php
class MyCompany_Categorywidget_Block_Catalog_Category_Info extends Mage_Core_Block_Template
{
protected $_category;
protected function _beforeToHtml()
{
$this->_category = $this->_prepareCategory();
return parent::_beforeToHtml();
}
protected function _prepareCategory()
{
$this->_validateCategory();
return Mage::getModel('catalog/category')->load($this->_getData('category'));
}
protected function _validateCategory()
{
if (! $this->hasData('category')) {
throw new Exception('Category must be set for info block');
}
}
public function getCategoryName()
{
return $this->_category->getName();
}
public function getCategoryImage()
{
return $this->_category->getImageUrl();
}
}
public function getCategoryUrl()
{
return $this->_category->getUrl();
}
app/design/frontend/base/default/template/categorywidget/info.phtml
<?php
$_categoryName = $this->getCategoryName();
$_categoryImage = $this->getCategoryImage();
?>
<div class="categoryinfo_block block">
<p><strong><?php echo $_categoryName ?></strong></p>
<img src="<?php echo $_categoryImage ?>" alt="<?php echo $_categoryName ?>" />
</div>
<?php
$_categoryName = $this->getCategoryName();
$_categoryImage = $this->getCategoryImage();
$_categoryUrl = $this->getCategoryUrl();
?>
<div class="categoryinfo_block block">
<p><strong><?php echo $_categoryName ?></strong></p>
<a href="<?php echo $_categoryUrl ?>" title="<?php echo $_categoryName ?>" alt="<?php echo $_categoryName ?>">
<img src="<?php echo $_categoryImage ?>" alt="<?php echo $_categoryName ?>" />
</a>
</div>
如果这对其他人有帮助?我如何获得我使用的类别的简短描述1.9我遵循了本教程-小部件出现在哪里?我尝试按照这些说明创建此模块。模块已安装,但小部件在magento管理中不可见。您确定它正常工作吗?