如何在magento中显示属性的url路径

时间:2014-05-24 11:34:14

标签: magento

$collection = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToFilter('level',array('eq'=>2))
    ->addAttributeToFilter('is_active',array('eq'=>1))
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('entity_id')
    ->addAttributeToSelect('url_path');

虽然打印$ collection我没有得到路径

1 个答案:

答案 0 :(得分:0)

我认为你需要这个。仔细阅读这个

 $_categories = Mage::getModel('catalog/category')->getCollection()
                     ->addAttributeToSelect('name')
                     ->addAttributeToSelect('is_active')
                     ->addUrlRewriteToResult();

<?php foreach($_categories as $_category): ?>
<a href="<?php echo $_category->getUrl($_category); ?>">
  <?php endforeach; ?>