ecshop 首页楼层下显示对应的品牌图标
1.效果:
2:源码分析;
html :
复制代码
<!--{if $goods_cat.id eq 951}-->
<!--{foreach from=$brands951 item=brandCat}-->
<a href="{$brandCat.url}" target="_blank"><img src="data/brandlogo/{$brandCat.brand_logo}" width="102" height="50" style="margin:5px;" /></a>
<!--{/foreach}-->
<!-- {/if}-->
<!--{if $goods_cat.id eq 950}-->
<!--{foreach from=$brands950 item=brandCat}-->
<a href="{$brandCat.url}" target="_blank"><img src="data/brandlogo/{$brandCat.brand_logo}" width="102" height="50" style="margin:5px;" /></a>
<!--{/foreach}-->
<!-- {/if}-->
<!--{if $goods_cat.id eq 1325}-->
<!--{foreach from=$brands1325 item=brandCat}-->
<a href="{$brandCat.url}" target="_blank"><img src="data/brandlogo/{$brandCat.brand_logo}" width="102" height="50" style="margin:5px;" /></a>
<!--{/foreach}-->
<!-- {/if}-->
<!--{if $goods_cat.id eq 688}-->
<!--{foreach from=$brands688 item=brandCat}-->
<a href="{$brandCat.url}" target="_blank"><img src="data/brandlogo/{$brandCat.brand_logo}" width="102" height="50" style="margin:5px;" /></a>
<!--{/foreach}-->
<!-- {/if}-->
<!--{if $goods_cat.id eq 732}-->
<!--{foreach from=$brands732 item=brandCat}-->
<a href="{$brandCat.url}" target="_blank"><img src="data/brandlogo/{$brandCat.brand_logo}" width="102" height="50" style="margin:5px;" /></a>
<!--{/foreach}-->
<!-- {/if}-->
<!--{if $goods_cat.id eq 1397}-->
<!--{foreach from=$brands1397 item=brandCat}-->
<a href="{$brandCat.url}" target="_blank"><img src="data/brandlogo/{$brandCat.brand_logo}" width="102" height="50" style="margin:5px;" /></a>
<!--{/foreach}-->
<!-- {/if}-->
复制代码
php :
复制代码
//////////////////////////////////////////////////////////////
/**
* 获得某个分类下的品牌 列表
*
* @access public
* @param int $cat
* @return array
*/
function get_cat_brands($cat = 0, $app = 'category')
{
$children = ($cat > 0) ? ' AND ' . get_children($cat) : '';
$sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, COUNT(g.goods_id) AS goods_num, IF(b.brand_logo > '', '1', '0') AS tag ".
"FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ".
$GLOBALS['ecs']->table('goods') . " AS g ".
"WHERE g.brand_id = b.brand_id $children " .
"GROUP BY b.brand_id ORDER BY b.sort_order ASC, tag DESC limit 12 ";
$row = $GLOBALS['db']->getAll($sql);
foreach ($row AS $key => $val)
{
$row[$key]['url'] = build_uri($app, array('cid' => $cat, 'bid' => $val['brand_id']), $val['brand_name']);
}
return $row;
}
调用:
$smarty->assign('brands951', get_cat_brands(951));
$smarty->assign('brands950', get_cat_brands(950));
$smarty->assign('brands1325', get_cat_brands(1325));
$smarty->assign('brands688', get_cat_brands(688));
$smarty->assign('brands732', get_cat_brands(732));
$smarty->assign('brands1397', get_cat_brands(1397));