前一侧面时间写过把PC上的楼层切换成函数,现在轮到手机版了,做了一个demo大家看下
{$lou=get_louceng(27) } {call name=louceng cat_goods=$lou.cat_goods goods_cat=$lou.goods_cat} {function name=louceng } <section class="index_floor_lou"> <div class="floor_body "> <h2> <em></em>{$goods_cat.name|escape:html}<span class="geng"><a href="../category.php?id={$goods_cat.id}" >更多 <i></i></a></span> </h2> {foreach from=$cat_goods item=goods name=name} <div class="pro_item"> <div class="products_kuang"> <a href="{$goods.url}" title="{$goods.name|escape:html}"><img src="{$option.static_path}{$goods.thumb}"></a> </div> <div class="goods_name">{$goods.name}</div> <div class="price"> {if $goods.promote_price}{$goods.promote_price}{else}{$goods.shop_price}{/if} <a href="javascript:addToCart({$goods.id})" class="btns"> <img src="themesmobile/68ecshopcom_mobile/images/index_flow.png"></a> </div> </div> {/foreach} </div> </section> {/function}
以上是模板部分,数据来源自php页面的函数
function get_louceng($louid) { $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style,g.goods_brief , g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, " . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' where 1=1 and is_on_sale=1 "; $sql= $sql." and g.cat_id in ({$louid}) "; $sql .="limit 0,6"; // echo $sql; $data['cat_goods']=get_goods($sql); $data['goods_cat']=array("name"=>"测试分类","id"=>27); return $data; }