Search code examples
magentomagento-1.4magento-1.5

To get tthe category url by using the category name


Is there any function in magento to get the category url by using the category name only. I know we can get the category url if we have the category id, but in my scenario, I have only the category name available. Any idea how to get this.


Solution

  • Given that category names aren't unique, you could use this to get the URL of the first match:

    $category = Mage::getModel('catalog/category')->load($name, 'name');
    if ($category->getId()) echo $category->getUrl() . "\n";