首页调用指定分类下子分类方法

模板首页一般都有分楼层显示的分类商品,每个楼层右上角会有该分类下小分类排列显示的:http://github.crmeb.net/u/defu

以往有些模板这里都是静态显示的,需要客户手动依次修改,现在模板中心告诉您怎样修改成动态调用,只需修改一个id即可。

1.打开您的文件根目录下 includes/lib_goods.php 文件,在最后一行加入一个方法:http://github.crmeb.net/u/defu

  function get_parent_id_tree($parent_id)
{
$three_c_arr = array();
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql))
{
$child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
'FROM ' . $GLOBALS['ecs']->table('category') .
"WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC ";
$res = $GLOBALS['db']->getAll($child_sql);
foreach ($res AS $row)
{
if ($row['is_show'])
$three_c_arr[$row['cat_id']]['id']   = $row['cat_id'];
$three_c_arr[$row['cat_id']]['name'] = $row['cat_name'];
$three_c_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
}
}
return $three_c_arr;
}
  1. 在模板文件里调用,如首页index.dwt中 :
 <?php
 $this->assign('thiscid1', get_parent_id_tree(17));//调用父级分类的下级分类
 ?>

 

   <!--{foreach from=$thiscid1 item=list name=name}-->
 <A href="{$list.url}" target=_blank >{$list.name}</A>
  <!--{/foreach}-->

括号里的“17”为分类id,按照您的网站商品分类修改此id即可。多个楼层就给不同名称赋值,如thiscid2、thiscid3…

3.去后台清除缓存。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CRMEB定制开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值