Showing results for 
Search instead for 
Did you mean: 

Hide category heading attribute if it's empty

Hide category heading attribute if it's empty

Hi folks,


Can someone please help me with the following. We display a list of categories the product belongs to in the following code. However, when there are no category headings the "Application Guide" row still appears. I believe we need some sort of an "if" statement but I tried everything and couldn't make it work. Basically, I need the Application Guide row to disappear if there are no Category Headings for the product.


The regular attributes do hide if they are empty.



    $_helper = $this->helper('catalog/output');
    $_product = $this->getProduct();
	$currentCatIds = $_product->getCategoryIds();
	$catCollection = Mage::getResourceModel('catalog/category_collection')
	->addAttributeToFilter('entity_id', $currentCatIds)
	->addAttributeToFilter('is_active', 1)
	->setOrder('creareseo_heading', 'asc')
<?php if($_additional = $this->getAdditionalData()): ?>
    <h2><?php echo $this->__('Additional Information') ?></h2>
    <table class="data-table" id="product-attribute-specs-table">
        <col width="25%" />
        <col />
        <?php foreach ($_additional as $_data): ?>
        <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
		if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
                <th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
                <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
        <?php } ?>
		<?php endforeach; ?>
                <th class="label"><?php echo $this->__('Application Guide') ?></th>
                <td class="data">
                    <?php foreach($catCollection as $cat): ?>
                        <li><?php echo $cat->getCreareseoHeading() ?></li>
                    <?php endforeach; ?>
    <script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>

Thanks in advance!



Re: Hide category heading attribute if it's empty


Please use

$_additional = $this->getAdditionalData();
your code

instaed of

if($_additional = $this->getAdditionalData()):


Found something useful, please give "Kudos" or "Accept as Solution" for Token of Appreciation.
Free Magento Extensions :

Re: Hide category heading attribute if it's empty

Please download the code from the link provided here and paste into your magento root directory.


Hope this helps!

Query solved? Accept as Solution.Thanks
Eric Baily