I'm trying to display a custom attribute on the category page. It works fine but when customer uses the search field, it displays the error "Fatal error: Call to a member function getId() on a non-object". My code is below. Any help is greatly appreciated.
$_category = Mage::registry('current_category');
<?php if ($_category->getId() && $_category->getCustomAttribute()): ?>
<div>
<?php echo $_helper->categoryAttribute($_category, $_category->getCustomAttribute(), 'custom_attribute') ?>
</div>
<?php endif; ?>
Solved! Go to Solution.
Try this code because this code is causing the errors $_category->getId()
$_category = Mage::registry('current_category');
<?php if (Mage::registry('current_category')): ?>
<div>
<?php echo $_helper->categoryAttribute($_category, $_category->getCustomAttribute(), 'custom_attribute') ?>
</div>
<?php endif; ?>
Try this code because this code is causing the errors $_category->getId()
$_category = Mage::registry('current_category');
<?php if (Mage::registry('current_category')): ?>
<div>
<?php echo $_helper->categoryAttribute($_category, $_category->getCustomAttribute(), 'custom_attribute') ?>
</div>
<?php endif; ?>
This helped! Thank you!