Get Magento category attribute in frontend

11,334

Solution 1

Try this:

$cat_attr = $this->getCurrentCategory()->getAttributes();
if(array_key_exists('short_description', $cat_attr)):
    $_shortDescription=$cat_attr['short_description']->getFrontend()->getValue($_category);
endif;

Solution 2

First thing I would do is do the following code on your category object

print_r($category->debug());

This will show you if that attribute is being loaded. If you don't see your attribute, you can go back to the controller where the object is being loaded and add it to your select by adding one of these lines:

->addAttributeToSelect('your_attribute')

That should load your attribute for you.

Solution 3

I had a custom attribute and got it shown in frontend this way;

$category_id = '10';
$attribute_code = 'category_categorycolor';
$category = Mage::getModel('catalog/category')->load($category_id);

echo $category->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($category);

Solution 4

Quite Simple

<?php foreach ($this->getStoreCategories() as $cat): ?>
<?php  $_category=Mage::getModel("catalog/category")->load($cat->getId()); ?>

now you should use getImage method to retrive your img attribute

<img src="<?php  echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/category/' . $_category->getImage() ?>" />

<?php endforeach ?>
Share:
11,334
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I have created a Category's attribute that I want to use on the frontend. I tried to access it the same way as we do for products but it doesn't seem to be working. How can I show the custom attribute on the frontend? Any guesses?

    Thanks