ecshop调用指定商品分类下固定条数的商品品牌列表

本文介绍如何通过二次开发,在ECSHOP首页调用指定分类下的品牌列表,包括添加自定义函数及在模板中进行调用的方法。

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

通过二次开发可以实现ECSHOP首页调用指定分类下的品牌列表。

第一步:
打开根目录下的index.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 HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC";
$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;

    }

这是调用所有分类品牌,如果要调用指定条数,直接在sql后面加limit即可

第二步:
在index.dwt 模板里使用以下代码调用:

<!--{foreach from=get_cat_brands($this->_var['cat']['id']) item=brandCat}-->
<li>
<a href="{$brandCat.url}">
<img  src="data/brandlogo/{$brandCat.brand_logo}" title="{$brandCat.brand_name}" width="106" height="36">
<span>{$brandCat.brand_name}</span>
</a>
</li>
<!--{/foreach}-->

需要指定分类ID调用,只要把代码中的

$this->_var['cat']['id']

改成 ID号就行,比如:调用ID=1的分类

<!--{foreach from=get_cat_brands(1) item=brandCat}-->
<li>
<a href="{$brandCat.url}">
<img  src="data/brandlogo/{$brandCat.brand_logo}" title="{$brandCat.brand_name}" width="106" height="36">
<span>{$brandCat.brand_name}</span>
</a>
</li>
<!--{/foreach}-->

文章精选自【blog.4ud.cn】

Action() { web_add_cookie("ECS_ID=d3a982c70109359a9e4b14c349b7a8f43fc01bb3; DOMAIN=192.168.77.133"); web_add_cookie("ECS[visit_times]=1; DOMAIN=192.168.77.133"); web_add_auto_header("Accept-Language", "zh-CN,zh;q=0.9"); web_url("ecshop", "URL=http://192.168.77.133/ecshop/", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=", "Snapshot=t1.inf", "Mode=HTML", EXTRARES, "Url=themes/default/images/topNavBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/foucsBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/NavBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/box_2Bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/h3title.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/bnt_search.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/lineBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/catBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/itemH2Bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/topNavR.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/searchBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/inputbg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=data/flashdata/dynfocus/data.js", ENDITEM, "Url=themes/default/images/helpTitBg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/logo1.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/footerLine.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/uh_bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/bnt_ur_log.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/ur_bg.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, "Url=themes/default/images/ur_bg1.gif", "Referer=http://192.168.77.133/ecshop/themes/default/style.css", ENDITEM, LAST); web_url("bnt_log.gif", "URL=http://192.168.77.133/ecshop/user.php", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/", "Snapshot=t2.inf", "Mode=HTML", LAST); web_set_sockets_option("SSL_VERSION", "AUTO"); lr_think_time(15); web_submit_data("user.php", "Action=http://192.168.77.133/ecshop/user.php", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/user.php", "Snapshot=t3.inf", "Mode=HTML", ITEMDATA, "Name=username", "Value=test0042", ENDITEM, "Name=password", "Value=123456", ENDITEM, "Name=act", "Value=act_login", ENDITEM, "Name=back_act", "Value=http://192.168.77.133/ecshop/", ENDITEM, "Name=submit", "Value=", ENDITEM, LAST); web_url("诺基亚E66", "URL=http://192.168.77.133/ecshop/goods.php?id=9", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/", "Snapshot=t4.inf", "Mode=HTML", LAST); web_url("cron.php", "URL=http://192.168.77.133/ecshop/api/cron.php?t=1753254435", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t5.inf", "Mode=HTML", EXTRARES, "Url=../themes/default/images/commentsBnt.gif", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", ENDITEM, LAST); web_url("goods.php", "URL=http://192.168.77.133/ecshop/goods.php?act=price&id=9&attr=227&number=1&1753254436206206", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t6.inf", "Mode=HTML", LAST); web_custom_request("flow.php", "URL=http://192.168.77.133/ecshop/flow.php?step=add_to_cart", "Method=POST", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t7.inf", "Mode=HTML", "Body=goods={\"quick\":1,\"spec\":[\"227\"],\"goods_id\":7,\"number\":\"1\",\"parent\":0}", LAST); web_url("flow.php_2", "URL=http://192.168.77.133/ecshop/flow.php?step=cart", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/goods.php?id=9", "Snapshot=t8.inf", "Mode=HTML", LAST); web_url("checkout", "URL=http://192.168.77.133/ecshop/flow.php?step=checkout", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=cart", "Snapshot=t9.inf", "Mode=HTML", LAST); web_url("flow.php_3", "URL=http://192.168.77.133/ecshop/flow.php?step=select_shipping&shipping=5&1753254446354354", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t10.inf", "Mode=HTML", LAST); web_url("flow.php_4", "URL=http://192.168.77.133/ecshop/flow.php?step=select_payment&payment=1&1753254449555555", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t11.inf", "Mode=HTML", LAST); web_url("flow.php_5", "URL=http://192.168.77.133/ecshop/flow.php?step=select_pack&pack=0&1753254451388388", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t12.inf", "Mode=HTML", LAST); web_url("flow.php_6", "URL=http://192.168.77.133/ecshop/flow.php?step=select_card&card=0&1753254453200200", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t13.inf", "Mode=HTML", LAST); web_url("flow.php_7", "URL=http://192.168.77.133/ecshop/flow.php?step=check_surplus&surplus=0&1753254455323323", "TargetFrame=", "Resource=0", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t14.inf", "Mode=HTML", LAST); web_submit_data("flow.php_8", "Action=http://192.168.77.133/ecshop/flow.php?step=done", "Method=POST", "TargetFrame=", "RecContentType=text/html", "Referer=http://192.168.77.133/ecshop/flow.php?step=checkout", "Snapshot=t15.inf", "Mode=HTML", ITEMDATA, "Name=shipping", "Value=5", ENDITEM, "Name=payment", "Value=1", ENDITEM, "Name=pack", "Value=0", ENDITEM, "Name=card", "Value=0", ENDITEM, "Name=card_message", "Value=", ENDITEM, "Name=bonus", "Value=0", ENDITEM, "Name=bonus_sn", "Value=", ENDITEM, "Name=postscript", "Value=", ENDITEM, "Name=how_oos", "Value=0", ENDITEM, "Name=x", "Value=91", ENDITEM, "Name=y", "Value=20", ENDITEM, "Name=step", "Value=done", ENDITEM, LAST); return 0; } 在此代码中,为什么关联不到ECS_ID
最新发布
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值