© 2005-2020 万博体育官网模板堂 版权所有,并保留所有权利。
专注模板制作、二次开发服务!
商品详细页调用当前子分类下的所有分类
先看效果:
操作方法:
第一:在goods.php的最下面添加一个function
//获取相关栏目的分类
function
get_categorys_info(http://www.ecshop.co/files/
$parent_id
)
{
http://www.ecshop.co/files/
$sql
=
"SELECT * FROM "
. http://www.ecshop.co/files/
$GLOBALS
[
'ecs'
]->table(http://www.ecshop.co/files/
'category'
) .
" WHERE parent_id="
.http://www.ecshop.co/files/
$parent_id
.
" ORDER BY sort_order asc"
;
http://www.ecshop.co/files/
$res
= http://www.ecshop.co/files/
$GLOBALS
[
'db'
]->getAll(http://www.ecshop.co/files/
$sql
);
http://www.ecshop.co/files/
$categorys
=
array
();
foreach
(http://www.ecshop.co/files/
$res
AS http://www.ecshop.co/files/
$idx
=> http://www.ecshop.co/files/
$row
){
http://www.ecshop.co/files/
$categorys
[http://www.ecshop.co/files/
$idx
][
'id'
] = http://www.ecshop.co/files/
$row
[
'cat_id'
];
http://www.ecshop.co/files/
$categorys
[http://www.ecshop.co/files/
$idx
][
'url'
] = build_uri(http://www.ecshop.co/files/
'category'
,
array
(
'cid'
=>http://www.ecshop.co/files/
$row
[
'cat_id'
]), http://www.ecshop.co/files/
$row
[
'cat_name'
]);
http://www.ecshop.co/files/
$categorys
[http://www.ecshop.co/files/
$idx
][
'name'
] = http://www.ecshop.co/files/
$row
[
'cat_name'
];
}
return
$categorys
;
}
第二:在然后我们需要获取这个栏目的父级,在顶部获取到这个栏目的父级
$cat_id
= http://www.ecshop.co/files/
$db
->getOne(
"SELECT cat_id FROM "
. http://www.ecshop.co/files/
$ecs
->table(http://www.ecshop.co/files/
'goods'
) .
" WHERE goods_id = '$goods_id' "
);
$parent_id
= http://www.ecshop.co/files/
$db
->getOne(
"SELECT parent_id FROM "
. http://www.ecshop.co/files/
$ecs
->table(http://www.ecshop.co/files/
'category'
) .
" WHERE cat_id = '$cat_id' "
);
第三:那么我们就拿$parent_id这个变量获取
$smarty
->assign(
'categorys_info'
, get_categorys_info(http://www.ecshop.co/files/
$parent_id
));
http://www.ecshop.co/files/
$smarty
->assign(
'cat_id'
, http://www.ecshop.co/files/
$cat_id
);
把他添加到smarty模板去赋值。
最后我们到我们自己的模板里面把他循环出来
{foreach from=$categorys_info item=r}
{if $cat_id!=$r[id]}
<
li
><
a
href
=
"{$r.url}"
title
=
"{$r.name}"
>{$r.name}</
a
></
li
>
{/if}
{/foreach}
很多人问为什么还要加个if去判断呢,因为你循环出来的是全部,你要把本身自己的栏目T出去。