ECshop 默认的商品自定义属性是一次性输出的,想要单独调用某个属性就需要动动手术了。
第一步:打开 includes\lib_insert.php 文件,在最后面 ?> 前面加入以下代码:注意,在在 ?> 前面。
/*调用商品属性*/ function insert_attr(arr) { staticstatic_res = NULL; aid= isset(arr['aid'])?arr['aid']:0;gid= isset(arr['gid'])?arr['gid']:0; if(aid==0) return ''; if (static_res[aid][gid] === NULL) { if(gid>0) {static_res[aid][gid] = GLOBALS['db']->getOne('select attr_value from ' .GLOBALS['ecs']->table('goods_attr') . " where attr_id ='aid' and goods_id='gid' "); } else { static_res[aid][gid] =GLOBALS['db']->getOne('select attr_name from ' . GLOBALS['ecs']->table('attribute') . " where attr_id ='aid' "); } } return static_res[aid][$gid]; }
每二步:在模板里调用,支持dwt与lib。
属性名称:{insert name=’attr’ aid=属性ID}
属性值:{insert name=’attr’ aid=属性ID gid=$goods_id}
$goods_id 是调用商品编号,也就是ID,不是货号。