ecshop教程

ECSHOP调用后台指定广告位下所有广告循环

ecshop教程 51源码 11-17 人阅读

ecshop调用后台指定广告位下所有广告循环

ecshop本身的广告调用规则是:对某个广告位下的广告列表随机显示其中一条。

而我们有时需要将某个广告位下的所有广告全部显示出来,那么如何处理呢,下面就自己做了一个函数:

 

\includes\lib_common.php  在最下面增加一个函数:根据传入的广告id,获取广告数组,全站通用。

 function get_position_ads($id)
 {
    $sql = "select * from " . $GLOBALS['ecs']->table('ad') . " where position_id = ".$id." AND enabled = 1 order by ad_id";
  $rows = $GLOBALS['db']->getAll($sql);
   if($rows )
   {
   $sql = "select ad_width,ad_height from " . $GLOBALS['ecs']->table('ad_position') . " where position_id = ".$id." limit 1";
   $ad_position = $GLOBALS['db']->getRow($sql);
   foreach($rows as &$row )
   {
  $row['pic']= 'data/afficheimg/'.$row['ad_code'];
   $row['width'] = $ad_position['ad_width'];
$row['height'] = $ad_position['ad_height'];
   }
  }
    return $rows;
 }

 

然后显示页加入smarty语句,

例如我们需要在首页加入一个广告列表,就在\index.php中查找assign_template();

 

在这句话的下面加入

$smarty->assign('addiy', get_position_ads(1));

 

最后在模板文件中把数据调用出来,这也是smarty引擎通用的方法。

打开\themes\default\index.dwt 模板,引入:

{foreach from=$addiy item=addiylist}<a href="{$addiylist.ad_link}" title="{$addiylist.ad_name}" target="_blank">
    <img src="{$addiylist.pic}" width="980" height="387" alt="{$addiylist.ad_name}" />
</a>{/foreach}


  签到得积分   积分充值