Janp95
Janp95

Reputation: 584

Select images from attribute value magento

I have this piece of code:

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') 
->setPageSize(4) 
->setCurPage(4); 

foreach ($collection as $product) {
$image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();

echo '<img src="'.$image.'" WIDTH=245 HEIGHT=245>';
}

This works perfect and show 4 product image's. How can i get 4 product images from the attribute color when it is equal to white ?

When i try this i get a error:

->addAttributeToSelect('color', 'white')

Upvotes: 0

Views: 262

Answers (1)

Shivam
Shivam

Reputation: 2443

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') 
->addAttributeToFilter('color', 'white')
->setPageSize(4) 
->setCurPage(4);

Upvotes: 1

Related Questions