本文共 1202 字,大约阅读时间需要 4 分钟。
首页的分类导购功能 代码如下:
$ids为catelog 数组
<div class="tan_tt">
<?php $ids = array(82,18,37); foreach($ids as $id){ $category = Mage::getModel('catalog/category')->load($id); //$layer = Mage::getSingleton('catalog/layer'); //$category = $layer->getCurrentCategory(); $_category = $category; // $_imgHtml = ''; $_imgUrl = $_category->getImageUrl(); echo '<div class="tan_s"><a href="'.$_category->getUrl().'"><img style="width:55px;height:55px;" src="'.$_imgUrl.'" /></a></div>'; echo '<div class="tan_gg"><a href="'.$_category->getUrl().'">'.$_category->getName().'</a></div>'; echo "<div class='tan_yy'>"; if($category->hasChildren()) { $ids = $category->getChildren(); $subCategories = Mage::getModel('catalog/category')->getCollection(); $subCategories->getSelect()->where("e.entity_id in ($ids)"); $subCategories->addAttributeToSelect('name'); $subCategories->load(); $jj = 1; foreach ($subCategories AS $item) { if($jj>6){ break; } echo " - " ; echo '<a href="'. $item->getUrl() . '">'; echo $item->getName(); echo "</a>("; echo $item->getProductCount(); //echo $item->getChildrenCount(); echo ")"; echo "<br/>"; $jj++; } echo " - <a href='". $_category->getUrl() . "'>More</a>"; } echo "</div>"; } ?> </div>
转载地址:http://bccli.baihongyu.com/