Magento 1.9 Category – Get Category URL from ID Without ?SID=

categorymagento-1.9

In Magento I have this to get the the url of a category from its ID

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

It works but at the end of url there is ?SID=somenumber.

I know I could remove it from

System > Configuration > Web > Session Validation Settings > Use SID on Frontend

But I want to keep it active, so how can i get the url of category without the ?SID=somenumber?

Best Answer

Using strpos and substr function, it works

$categoryLink = Mage::getModel("catalog/category")->load(10)->getUrl();
$pos = strpos($categoryLink, '?');
$categoryLink = ($pos>0) ? substr($categoryLink, 0, $pos) : $categoryLink;
Related Topic