On the category listing pages, I need to show the number of color options for each product in the list. How can I output that count?

I am using configurable products with the color options as simple products. The attribute ID of "color" is 80. The code would go inside this loop: <?php foreach ($_productCollection as $_product): ?>

1 Answer 1


I have found a solution:

$childIds = $_product->getTypeInstance(true)->getChildrenIds($_product->getId(), false); //$_product is defined in the loop
$colors = count($childIds[0]); //getChildrenIds() returns an encapsulated array
echo $colors.' Color';
if ($colors != 1) echo 's'; //make "Color" plural

This assumes that the color attribute is the only determining attribute for the configurable product.

  • I would like to improve this code to filter out disabled products if anyone has a suggestion. Nov 23, 2016 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.