首页的分类导购功能

本文介绍了一种使用PHP实现的首页分类导购功能,通过加载指定类别的产品,并展示类别名称及图片,同时列出子类别及其商品数量,为用户提供清晰的商品导航。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首页的分类导购功能 代码如下:

$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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值