Get Category Url from ID in Magento

Use the below code to get the category url from the category ID in magento

$category_id = 14;
Mage::getModel("catalog/category")->load($category_id)->getUrl();

Cheers!
Amjath

5 comments on “Get Category Url from ID in Magento

  1. Using Magento (Category-) models might become very heavy to load just for loading the URL of category. When you’re in a loop where you need to load the URL’s of 9000+ category URL’s you might consider using the url rewrite functionality to fetch the URL’s since it doesn’t involve loading numerous Magento models:


    $requestPath = Mage::getSingleton('core/url_rewrite')
    ->getResource()
    ->getRequestPathByIdPath(
    'category/' . $categoryId, Mage::app()->getStore()->getId());
    return Mage::getBaseUrl() . $requestPath;

    Read this article for more information on this one: http://gielberkers.com/get-magento-category-url-without-loading-category/

Leave a Reply to Keyur Shah Cancel reply

Your email address will not be published. Required fields are marked *