我有一个问题在类别名称上添加链接,我有以下代码
$sports = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
我的问题是如何在类别上添加链接。
之后是我的输出foreach($sports as $key => $value)
{
$data = $value->getData();
}
输出:
Array (
[entity_id] => 2
[entity_type_id] => 3
[attribute_set_id] => 3
[parent_id] => 1
[created_at] => 2016-02-29 13:39:10
[updated_at] => 2016-03-02 12:32:37
[path] => 1/2
[position] => 1
[level] => 1
[children_count] => 5
[is_active] => 1
[include_in_menu] => 1
[landing_page] => 4
[is_anchor] => 1
[custom_apply_to_products] => 0
[name] => Default Category
[meta_title] =>
[custom_design] =>
[page_layout] =>
[display_mode] => PRODUCTS_AND_PAGE
[available_sort_by] =>
[description] =>
[meta_keywords] =>
[meta_description] =>
[custom_layout_update] =>
[custom_design_from] =>
[custom_design_to] =>
[filter_price_range] =>
)
链接:
<li><a href="product.html"><?php echo strtoupper($data['name']);?></a></li>
答案 0 :(得分:0)
尝试此解决方案。
<?php
$sports = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
$_helper = Mage::helper('catalog/category'); //category helper
foreach($sports as $sport)
{
$_currentCat = Mage::getModel('catalog/category')->load($sport->getId()); //load current category
echo $_helper->getCategoryUrl($_currentCat); //Category URL
}
?>
您可以将此代码替换为product.html但请务必检查代码并进行相应的处理。
<?php echo $_helper->getCategoryUrl($_currentCat); ?>
希望这能帮到你!