调用ecshop某个广告分析

2011-10-06 22:56 来源:www.chinab4c.com 作者:ecshop专家

     在ecshop里面,广告管理非常简单,ecshop广告信息将广告和广告位置联合起来。只要在ecshop模板中设置广告位置,就能调用某个广告了。有关ecshop广告设置,请参考本文http://www.chinab4c.com/html/dianzishangwujiaocheng/ecshopjiaocheng/2011/0921/878.html

     如果要调用某个广告位下的广告,我们必须做以下操作。

    1:首先在ECSHOP的广告管理里面增加广告A,我们在找到该广告的广告位置。既在ecshop数据库表ad里面找出position的值。

    2:PHP里面写以下代码

     $time = gmtime();
    $sql  = 'SELECT a.ad_id, a.position_id, a.media_type, a.ad_link, a.ad_code, a.ad_name, p.ad_width, '.
                        'p.ad_height, p.position_style, RAND() AS rnd ' .
                    'FROM ' . $GLOBALS['ecs']->table('ad') . ' AS a '.
                    'LEFT JOIN ' . $GLOBALS['ecs']->table('ad_position') . ' AS p ON a.position_id = p.position_id ' .
                    "WHERE enabled = 1 AND a.position_id = '5' AND start_time <= '" . $time . "' AND end_time >= '" . $time . "' " .
                    'ORDER BY rnd LIMIT 1';
  $res = $GLOBALS['db']->getAll($sql);
 $ads = '';
    foreach ($res AS $row)
    {
        if ($row['position_id'] != '5')
        {
            continue;
        }
        $position_style = $row['position_style'];
        switch ($row['media_type'])
        {
            case 0: // 图片广告
                $src = (strpos($row['ad_code'], 'http://') === false && strpos($row['ad_code'], 'https://') === false) ?
                        DATA_DIR . "/afficheimg/$row[ad_code]" : $row['ad_code'];
                $ads = "<a href='affiche.php?ad_id=$row[ad_id]&amp;uri=" .urlencode($row["ad_link"]). "'
                target='_blank'><img src='$src' width='" .$row['ad_width']. "' height='$row[ad_height]' /></a>";
                break;
        
          
        }
    }
 $smarty->assign('ads_top',$ads);
 

   3:在ecshop模板中这样写就可以{$ads_top}

   以上就完成了ecshop某个广告的调用。

   来源: http://www.chinab4c.com