在做模板的时候我们可能会在楼层遇到二级分类logo图的调用,那么首先就需要我们在写楼层里调用商品分类名称等相关信息的方法时也将logo图调出来;其次是在调用的地方引用其路径即可。
下面我就以我的模板为例:我写的方法是
function get_child_cat( $tree_id = 0, $num = 0 )
{
$three_arr = array( );
$sql = "SELECT count(*) FROM ".$GLOBALS['ecs']->table( "category" ).( " WHERE parent_id = '".$tree_id."' AND is_show = 1 " );
if ( 0 < $num )
{
$where = " limit ".$num;
}
if ( $GLOBALS['db']->getOne( $sql ) || $tree_id == 0 )
{
$child_sql = "SELECT cat_id, cat_name, parent_id,thumb,is_show FROM ".$GLOBALS['ecs']->table( "category" ).( "WHERE parent_id = '".$tree_id."' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC {$where}" );
$res = $GLOBALS['db']->getAll( $child_sql );
foreach ( $res as $row )
{
if ( $row['is_show'] )
{
$three_arr[$row['cat_id']]['id'] = $row['cat_id'];
$three_arr[$row['cat_id']]['thumb'] = $row['thumb'];
$three_arr[$row['cat_id']]['name'] = $row['cat_name'];
$three_arr[$row['cat_id']]['url'] = build_uri( "category", array(
"cid" => $row['cat_id']
), $row['cat_name'] );
}
}
}
return $three_arr;
}
在楼层里调用二级分类logo的方法为 <img src="data/catthumb/{$cat_item.thumb}">;当然thumb前缀你要根据自己循环中所使用的item名称做出相应的改变即可。
建站咨询热线
18503087281