更新时间:2023-11-30 11:53:52
您的问题的解决方案如下.我不会使用mysql rand()函数,因为它相当慢.
The solution to your question is bellow. I wouldn't use mysql rand() function since it's quite slow.
<ul class="brand_list">
<?php
$media = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$parentCategory = Mage::getModel('catalog/category')->load(12);
$children = Mage::getModel('catalog/category')
->getCollection()
->addIdFilter( array_rand( array_flip( $parentCategory->getAllChildren( true ) ), 6) )
->addAttributeToSelect('name')
->addAttributeToSelect('thumbnail');
?>
<?php foreach ($children as $category): ?>
<li class="span3">
<a href="<?php echo $category->getUrl(); ?>">
<img alt="<?php echo $category->getName(); ?>" src="<?php echo $media; ?>catalog/category/<?php echo $category->getThumbnail(); ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>