ECShop实现产品页面上一个、下一个的链接地址带

2016-09-07 22:03 来源:www.chinab4c.com 作者:ecshop专家

1,在goods.php文件中,修改上一个下一个位置的代码

 

  1. /* 上一个商品下一个商品 */ 
  2.  
  3.         $prev_gid = $db->getRow("SELECT goods_id,goods_name 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");  
  4.  
  5.         if (!emptyempty($prev_gid))  
  6.  
  7.         {  
  8.                         $prev_good['goods_name'] = $prev_gid['goods_name'];  
  9.                           
  10.                         $prev_good['url'] = build_uri('goods'array('gid' => $prev_gid['goods_id']),$prev_gid['goods_name']);  
  11.  
  12.             $smarty->assign('prev_good'$prev_good);//上一个商品  
  13.  
  14.         }  
  15.  
  16.         $next_gid = $db->getone("SELECT max(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");  
  17.  
  18.         if (!emptyempty($next_gid))  
  19.  
  20.         {  
  21.  
  22.             $next_good['goods_name'] = $db -> getOne("select goods_name from ".$ecs->table('goods')." where goods_id =".$next_gid);          
  23.  
  24.             $next_good['url'] = build_uri('goods'array('gid' => $next_gid),$next_good['goods_name']);  
  25.  
  26.             $smarty->assign('next_good'$next_good);//下一个商品  
  27.         } 

 

2,在goods.dwt模版文件,在适当的位置加上:

  1. <br><hr color=red> 
  2.             {if $prev_good}  
  3.         【上一个礼品】<a href="{$prev_good.url}" title="{$prev_good.goods_name}" >{$prev_good.goods_name}</a> 
  4.         {/if}<br> 
  5.         {if $next_good}  
  6.         【下一个礼品】<a href="{$next_good.url}" title="{$next_good.goods_name}">{$next_good.goods_name}</a> 
  7.         {/if} 



3.demo 参见截图


 

4.作用:方便导航;利于SEO。欢迎大家意见和交流

 

(责任编辑:chinab4c)