很多文章也有调用同分类随机产品
但那只能调用到大类目自己修改了下调用相同子分类产品
<?php
$_categoryIds = $_product->getCategoryIds();
$categories = end($_categoryIds);
$category = Mage::getModel('catalog/category');
$category->load($categories);
$collection = $category->getProductCollection();
foreach ($collection as $product) {
$result[] = $product->getId();
}
?>
<div class="box-others-also-like">
<ul>
<?php
if(sizeof($result) >= 4)
{
$ourneed = array_rand($result,4);
foreach($ourneed as $cc)
{
$thisproduct= Mage::getModel('catalog/product')->load($result[$cc]);
?>
<li>
<a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(72) ?>" height="72" alt="<?php echo $thisproduct->getName(); ?>" /></a>
</li>
<?php } ?>
<?php
}else
{
foreach($result as $cc)
{
$thisproduct= Mage::getModel('catalog/product')->load($cc);
?>
<li>
<a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(72) ?>" height="72" alt="<?php echo $thisproduct->getName(); ?>" /></a>
</li>
<?php
}
}
?>
</ul>
</div>
<!--for show other product-->