Showing results for 
Search instead for 
Did you mean: 

Display Available Attribute Options on Category Page

Display Available Attribute Options on Category Page

This is probably an odd request. I'm no programmer but I have managed to make it this far.

For SEO purposes, we want to display our custom attribute options for the attribute product_type in the h1 title tag on each category page. So far we have been successful. However, it displays all of the attribute options. We only want to display the attribute options that have a product count of one or more.


  • Category Name
    • Category1
  • product_type Attribute Options (filtered to category)
    • A (2 products)
    • B (0 products)
    • C (5 products)
  • What should display in h1 tag
    • A, C for Category1

Like I said, we've been able to show all of the attribute options in the h1 tag but cannot figure out how to have it filter based on the attribute options that actually apply to that category.

The code below is what we currently have. Any help would be appreciated! Hopefully what we are trying to achieve makes sense.


		// specify the select or multiselect attribute code
		$attributeCode = 'product_type';

		// build and filter the product collection
		$products = Mage::getResourceModel('catalog/product_collection')
			->addAttributeToFilter($attributeCode, array('notnull' => true))
			->addAttributeToFilter($attributeCode, array('neq' => ''))

		$usedAttributeValues = array_unique($products->getColumnValues($attributeCode));

		// ---- this is the different part compared to the previous example ----

		// fetch the attribute model

		$attributeModel = Mage::getSingleton('eav/config')
		->getAttribute('catalog_product', $attributeCode);

		// map the option id's to option labels
		$usedAttributeValues = $attributeModel->getSource()->getOptionText(
			implode(',', $usedAttributeValues)

		$comma_separated = implode(', ', $usedAttributeValues);
		echo $comma_separated," for ";

		// $usedAttributeValues now contains an array of used values in human readable format
	<?php echo $category->getName(); ?>