Danijel Daxx Chalupka
Danijel Daxx Chalupka

Reputation: 55

Get category by url-key (Magento)

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

Answers (3)

kiatng
kiatng

Reputation: 3047

An easier method:

/** @var Mage_Catalog_Model_Category $category */
$category = Mage::getModel('catalog/category');
$category->loadByAttribute('url_key', 'buy-now');

Upvotes: 1

Amit Bera
Amit Bera

Reputation: 7611

enter image description here iF url key $urlkey = 'shirt';

Mage::getModel('catalog/category')->getCollection()
                ->addNameToResult()
                ->addUrlRewriteToResult()
               ->addAttributeToFilter('url_key',$urlkey )
            ->getFirstItem();

Upvotes: 5

Lukas Kral
Lukas Kral

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

Related Questions