user493453
user493453

Reputation: 21

Get Magento category attribute in frontend

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

Upvotes: 2

Views: 11516

Answers (4)

Anil Prz
Anil Prz

Reputation: 1139

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);

Upvotes: 2

Jonathan Day
Jonathan Day

Reputation: 18692

Try this:

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

Upvotes: 6

Antonino Bonumore
Antonino Bonumore

Reputation: 797

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 ?>

Upvotes: 1

Josh Pennington
Josh Pennington

Reputation: 6408

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.

Upvotes: 3

Related Questions