Get URL and Magento Category Name

I would like to add a few category links with names manually in my multi-line. I tried this (example ID20 category example)

<?php $category = Mage::getModel('catalog/category')->load(20); ?> <a href="<?php echo $category->getUrl(); ?>"><?php echo $category->getName();?></a> 

This works, but I'm not sure if this is a good idea, there are many downloads to get the URL.

I also tried using translation:

 <a href="<?php echo $this->__('URL-Language1') ?>"><?php echo $this->__('CatName-Language1') ?></a> 

Translated to Locale csv.

It also works, but what is the β€œright way” to achieve this? This seems like a workaround.

+5
source share
1 answer

You can try the following:

 Mage::getResourceModel('catalog/category')->getAttributeRawValue($categoryId, 'name', $storeId); 

to get an attribute of any category (in this case) also ($categoryId, 'url_key', $storeId) for the url key attribute, but it's just the URL is not the full URL of the category.

0
source

Source: https://habr.com/ru/post/1259062/


All Articles