Reputation: 55
I'm trying to get exact category from all categories and list subcategories into a page.
How to get category by it's url-key, not url-key from category?
Thanks
Upvotes: 3
Views: 7652
Reputation: 3047
An easier method:
/** @var Mage_Catalog_Model_Category $category */
$category = Mage::getModel('catalog/category');
$category->loadByAttribute('url_key', 'buy-now');
Upvotes: 1
Reputation: 7611
iF url key $urlkey = 'shirt';
Mage::getModel('catalog/category')->getCollection()
->addNameToResult()
->addUrlRewriteToResult()
->addAttributeToFilter('url_key',$urlkey )
->getFirstItem();
Upvotes: 5
Reputation: 997
You can get the category model by url key using this code:
$category = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToFilter('url_key', 'your-url-key')
->getFirstItem();
Upvotes: 1