在 magento 类别上添加超链接


Add hyper link on magento categories

我有一个问题,为此在类别名称上添加链接,我有以下代码

$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>

试试这个解决方案。

<?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
}
?>

您可以将此代码代替产品.html但请务必检查代码并相应地放置。

<?php echo $_helper->getCategoryUrl($_currentCat);  ?>

希望对您有所帮助!