cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Attribute on Category Page

SOLVED

Custom Attribute on Category Page

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; ?>
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Custom Attribute on Category Page

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

 

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

View solution in original post

2 REPLIES 2

Re: Custom Attribute on Category Page

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

 

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: Custom Attribute on Category Page

This helped! Thank you!