ecshop的首页主广告轮播替换为js翻转效果,最模板方法二

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

 找到ecshop 程序,打开模板index_ad.lbi,输入或替换以下代码:

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<!-- {if $index_ad eq 'sys'} -->

  <script type="text/javascript">

   var swf_width=725;

   var swf_height=300;

  </script>

  <script type="text/javascript" src="data/flashdata/{$flash_theme}/cycle_image.js"></script>

<!-- {elseif $index_ad eq 'cus'} -->

<?php

 

if(!function_exists("get_ads")){

function get_ads($num)

{

$sql = 'select * from '.$GLOBALS['ecs']->table('ad_custom').' ORDER BY add_time DESC';

 

  if ($num > 0)

  {

   $sql .= ' LIMIT ' . $num;

  }

  //echo $sql;

        

  $res = $GLOBALS['db']->getAll($sql);

  $ads = array();

  foreach ($res AS $idx => $row)

  {

 

   $ads[$idx]['ad_name']       = $row['ad_name'];

   $ads[$idx]['content']         = $row['content'];

   $ads[$idx]['url']        = $row['url'];

 

  }

  return $ads;

}

}

 

 $this->assign('my_ads',get_ads(9)); // 9代表会条数据

?>

  <!-- nav middle right ad box  div end -->

  <div class="nav_leftbox">

    <!-- nav left box menu div start -->

    <div class="nav_leftmenu">

  <!--{foreach from=$my_ads item=ads name=ad_num}-->

     <!-- {if $smarty.foreach.ad_num.iteration le 5}-->

    <span id="leftmenu_content{$smarty.foreach.ad_num.iteration}"<!-- {if $smarty.foreach.ad_num.iteration eq 1}--> style="display:block"<!-- {/if}-->><a href="{$ads.url}" target="_blank" title="{$ads.ad_name}"><img src="{$ads.content}" /></a></span> 

      <!-- {/if}-->

  <!--{/foreach}-->

      <div class="nav_lefttab">

  <!--{foreach from=$my_ads item=ads name=ad_num}-->

     <!-- {if $smarty.foreach.ad_num.iteration le 5}-->

      <a id="leftmenu_tab{$smarty.foreach.ad_num.iteration}"<!-- {if $smarty.foreach.ad_num.iteration eq 1}--> class="thisselected"<!-- {/if}--> href="{$ads.url}" target="_blank" onmouseover="chooseLeftMenu({$smarty.foreach.ad_num.iteration})"><font color="white">{$ads.ad_name}</font></a>

      <!-- {/if}-->

  <!--{/foreach}-->

      </div>

    </div>

  </div>

  <!-- nav left box menu div end -->

<script>

function chooseLeftMenu(id){

    for (var i = 1; i <= 5; i++){

   if (i == id){

       $('leftmenu_tab'+i).className = 'thisselected';

       $('leftmenu_content'+i).fade('in');

       $('leftmenu_content'+i).style.display = 'block';

   }else{

       $('leftmenu_tab'+i).removeClass('thisselected');

       $('leftmenu_content'+i).fade('out');

       $('leftmenu_content'+i).style.display = 'none';

   }

}

}

</script>

  <div class="nav_middlebox">

    <!-- nav middle focus box  div start -->

    <div id="f_a" class="focusimg">

  <!--{foreach from=$my_ads item=ads name=ad_num}-->

     <!-- {if $smarty.foreach.ad_num.iteration ge 6}-->

      <!-- {if $smarty.foreach.ad_num.iteration eq 6}--><div style="display:block;"><!-- {else}--><div style="display:none;"><!-- {/if}--><a target="_blank" href="{$ads.url}"><img border="0" onmouseout="setAuto();" onmouseover="clearAuto();" src="{$ads.content}"/></a></div>

      <!-- {/if}-->

  <!--{/foreach}-->

      <div class="focusimg_number">

        <table cellspacing="1" cellpadding="0" border="0" align="right" id="num_tag" height="30">

          <tr>

<!--{foreach from=$my_ads item=ads name=ad_num}-->

 <!-- {if $smarty.foreach.ad_num.iteration ge 6}-->

    <!-- {if $smarty.foreach.ad_num.iteration eq 6}-->

       <td align="center" width="130" style="cursor:pointer;" onmouseout="setAuto();" onmouseover="clearAuto(0);" onclick="Mea(0);" class="bigon">{$ads.ad_name}</td>

    <!-- {elseif $smarty.foreach.ad_num.iteration eq 7}-->

        <td align="center" width="130" style="cursor:pointer;" onmouseout="setAuto();" onmouseover="clearAuto(1);" onclick="Mea(1);" class="bigoff">{$ads.ad_name}</td>

    <!-- {elseif $smarty.foreach.ad_num.iteration eq 8}-->

        <td align="center" width="130" style="cursor:pointer;" onmouseout="setAuto();" onmouseover="clearAuto(2);" onclick="Mea(2);" class="bigoff">{$ads.ad_name}</td>

    <!-- {else}-->

        <td align="center" width="130" style="cursor:pointer;" onmouseout="setAuto();" onmouseover="clearAuto(3);" onclick="Mea(3);" class="bigoff">{$ads.ad_name}</td>

    <!-- {/if}-->

  <!-- {/if}-->

<!--{/foreach}-->

          </tr>

        </table>

      </div>

    </div>

  </div>

  <!-- nav middle focus box  div end -->

<script type="text/javascript">var n=0;var t=4;var showNum=document.getElementById("num_tag"); function Mea(value){n=value;setBg(value);plays(value);} function setBg(value){for(var i=0;i<t;i++)if(value==i){showNum.getElementsByTagName("td")[i].className='bigon';}else{showNum.getElementsByTagName("td")[i].className='bigoff';}} function plays(value){try{with(f_a){children[value].getElementsByTagName("img")[0].filters[0].Apply();for(i=0;i<t;i++)i==value?children[i].style.display="block":children[i].style.display="none";children[value].getElementsByTagName("img")[0].filters[0].Play();}}catch(e){var divlist=document.getElementById("f_a").getElementsByTagName("div");for(i=0;i<t;i++){i==value?divlist[i].style.display="block":divlist[i].style.display="none";}}} function clearAuto(k){clearInterval(autoStart);if(k != null)Mea(k);}function setAuto(){autoStart=setInterval("auto(n)", 5000);}function auto(){n++;if(n>t-1)n=0;Mea(n);}function sub(){n--;if(n<0)n=t-1;Mea(n);} setAuto();</script>

<!-- {/if} -->

 

这里加了个函数 get_ads,调用后台自定义广告zuimoban_ad_custom表,具体长高度自行替换!chinab4c提供!

 

(责任编辑:chinab4c)