I'm trying to display related products in the product view page. I created a collection of them but when i try to fetch them, the getName() method renders the correct name but getProductUrl() renders the url of the parent product. Here is my code:
$categoryId = array_shift($_product->getCategoryIds());
$related_prods = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addUrlRewrite($categoryId)
->addAttributeToFilter('entity_id',array('in'=>$_product->getRelatedProductIds()))->load();
<div>
<?php foreach($related_prods as $related){ ?>
<a href="<?php $this->getUrl('books').$related->getUrlPath()."<br />";?>"><?php echo $related->getName();?></a>
<?php } ?>
</div>
Thanks in advance.