ecshop在商品详情页调用该商品所属分类名称
在 ecshop 商品详情页面是不显示该商品所属分类名称的,哦,对了,不能说不完全显示,是没有单独的调用显示出来,其实在当前位置已经显示出来了,比如最近刚给在单位做的精品购物站的详情页面,显示如“当前位置: 首页 > 设计印刷 > 宣传画册 > 宣传画册02”,在这里已经显示出来了,但我们有时候还需要在商品详情属性这里显示一个单独的分类名称,下面小虎博客就来分享一下如何在商品详情页显示出来。
第一步,打开 goods.php 文件,在页面里面添加如下代码:
[code lang="php"]
function get_cat_info($cat_id)
{
return $GLOBALS['db']->getOne('SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') .
" WHERE cat_id = '$cat_id'");
}
[/code]
第二步,搜索代码:
$smarty->assign('goods_rank',get_goods_rank($goods_id));
在这段代码的下面添加如下代码:
[code lang="php"]
$sql= "select cat_id from ".$GLOBALS['ecs']->table('goods')."where goods_id ='".$goods_id."'";
$thiscat_id = $GLOBALS['db']->getOne($sql);
$smarty->assign('thiscat_id', $thiscat_id);
$smarty->assign('thiscat_name', get_cat_info($thiscat_id));
[/code]
第三步,OK,这个时候就可以在商品详情模板页面调用该商品的分类ID以及名称了,标签如下:
[code lang="php"]
{$thiscat_id} 该商品分类ID
{thiscat_name} 该商品所属分类名称
[/code]