影子互联

专注深圳网站建设

ecshop商品详情页添加上一个下一个商品导航方法

时间:2016-12-28 16:55:16,点击:0

 ecshop商品详情页添加上一个下一个商品导航方法

修改goos.php文件中代码

修改后如下:

         /* 上一个商品下一个商品 */
        $prev_gid = $db->getOne("SELECT goods_id FROM " .$ecs->table('goods'). " WHERE cat_id=" . $goods['cat_id'] . " AND goods_id > " . $goods['goods_id'] . " AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 LIMIT 1");
        if (!empty($prev_gid))
        {
            $prev_good['url'] = build_uri('goods', array('gid' => $prev_gid), $goods['goods_name']);
            $prev_good['goods_name'] = $db -> getOne("select goods_name from ".$ecs->table('goods')." where goods_id =".$prev_gid); 
            $smarty->assign('prev_good', $prev_good);//上一个商品
        }
        $next_gid = $db->getOne("SELECT max(goods_id) FROM " . $ecs->table('goods') . " WHERE cat_id=".$goods_info['cat_id']." AND goods_id < ".$goods_info['goods_id'] . " AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0");
        if (!empty($next_gid))
        {
            $next_good['url'] = build_uri('goods', array('gid' => $next_gid), $goods['goods_name']);
            $next_good['goods_name'] = $db -> getOne("select goods_name from ".$ecs->table('goods')." where goods_id =".$next_gid); 
            $smarty->assign('next_good', $next_good);//下一个商品
        }
        

 

模板中调用

<p style="margin: 5px 0;font-size: 12px;line-height: 1.3;">
{if $prev_good}  
    【上一个】<a href="{$prev_good.url}" title="{$prev_good.goods_name}" >{$prev_good.goods_name}</a> 
{else} 
    【上一个】没有了 
{/if}<br> 
{if $next_good}  
    【下一个】<a href="{$next_good.url}" title="{$next_good.goods_name}">{$next_good.goods_name}</a> 
{else} 
    【下一个】没有了 
{/if} 
</p>

 

 

刷新前台查看。