Q:

Magento ->addAttributeToFilter - removing selected product from collection

I'm looking to make a simple related products block on my product page, we have a vast amount of products so at the moment it's not really feasible to use the backend entry of upsells etc.
Below i've some code which selects similar products via the use of 'prod_colour' - so if a person is viewing a product of beige colour, it returns all beige coloured products in the category, then chooses 4 by random to show.
<?php

$thiscolour = $_helper->productAttribute($_product, $_product->getProd_colour(), 'prod_colour');
$bestsellers=Mage::getModel('catalog/category')->load(3);
$collection=$bestsellers->getProductCollection();
$collection->addAttributeToFilter('prod_colour', $thiscolour);
$collection->addAttributeToSelect('small_image');
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$collection->getSelect()->limit(4);

?>

I'm just wondering how it's possible to remove the currently viewed product from the collection - for example if i'm viewing product 1, and products 1, 3, 5 , 7 are all the same colour, it returns all four products - i'd be looking to remove product 1 so the block will only show products 3, 5 and 7.
Thanks for reading!

A:

You are on product page so you get product id so you can use below filter condition on product collection
addAttributeToFilter('id', array('neq' => 'yourid'));

For further condition you can check here

