看到不少朋友在找首页特价商品倒计时的修改方法,写了这篇文章希望能帮到有此需要的朋友们
% ?5 m$ f } o
g" W0 }8 ^# ]3 s
) |! @' \! i" B/ a, J& N) D! f' ], p5 `( I. c ?$ V
1、首先修改程序部分- d6 f( n/ i3 v, O- c
打开includes/lib_goods.php
' k. n7 G2 O5 v* Z, d6 Q# T- U找到get_promote_goods()函数部分
4 c3 s/ {/ w+ r. K: ~+ S在
/ [0 v- n% k7 z9 x6 F( k. w$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); | 0 D; W6 Q# t" B: f: i8 o
(注:这里一定要谨慎,一定要找准位置,很多同志都是绊倒在这里的,如果你没修改过这个文件的话,大概是在394行的位置,找错了就出不来了)1 m1 o+ h: s' Z7 \( ] `. E/ j
下面增加代码/* 促销时间倒计时 */
6 ~% O8 Y# I0 h/ i7 q5 C $time = gmtime();4 e$ ?" n \# x+ K% T v
if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date']), C' ?9 K0 |9 Y; D4 x" ^3 s& ]
{4 j4 o8 N* i0 I* [4 O" \
$goods[$idx]['gmt_end_time'] = local_date('M d, Y H:i:s',$row['promote_end_date']);- `+ b2 d1 l4 h9 Y, J4 Q
}
- ]0 I _0 \3 I. n- T else' Z. r$ J' u/ X
{) h" p! N J1 O
$goods[$idx]['gmt_end_time'] = 0;
: x7 ^- }! o0 y" `- n b6 M } | : C( p8 T3 E6 D
7 ?4 z/ v; q r3 [) ~: o) F! M2、
1 M4 o9 U6 V& N- m然后将 library/recommend_promotion.lbi# V6 Q6 h* g- z
全部替换为下面代码: j" \! Y" @' E7 R- O
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
! U/ ~$ }( a% v. a<!-- {if $promotion_goods} -->
: M7 U4 t4 x4 f3 c7 ^7 r @<script >, n3 x( J8 c, w$ @/ g( f7 i
var Tday = new Array();& h$ n1 A% H% s0 B: [% g
var daysms = 24 * 60 * 60 * 10003 ^. O( K, P7 J6 w5 e L" i
var hoursms = 60 * 60 * 1000 i v+ r( ?& e8 f; B7 P
var Secondms = 60 * 1000
/ {1 F z- y' \5 A* D3 y5 I& b. q) Svar microsecond = 1000
$ b V( _8 T- S& B: t, x$ L9 m% Vvar DifferHour = -1
+ d; \: p% C5 r T% A4 m& V$ ^var DifferMinute = -1, A7 f% j% C/ X" t: ?$ y4 S# a4 a+ y
var DifferSecond = -1
1 p4 |( `% Y" n; Mfunction clock(key)
! B. A( O* \4 M4 ?7 H {
! j- O5 ?; q" ~: f! r, W! S6 a var time = new Date()
4 R3 P, B0 |4 c7 K' G var hour = time.getHours()9 t4 |' P2 b7 m5 U
var minute = time.getMinutes()9 h- ^4 |' U2 p' I& q
var second = time.getSeconds()/ G7 H+ ]7 u0 W6 a
var timevalue = ""+((hour > 12) ? hour-12:hour)
/ a* P6 c$ r% d, P3 m timevalue +=((minute < 10) ? ":0":":")+minute
( t1 k# I4 [' y7 w timevalue +=((second < 10) ? ":0":":")+second S; ~! _# v+ c+ Q( Y
timevalue +=((hour >12 ) ? " PM":" AM")* h" C8 S; `, V* M7 }
var convertHour = DifferHour
2 P n) k8 t: l" ~' ] var convertMinute = DifferMinute" P2 P6 f! w1 e d% I
var convertSecond = DifferSecond7 _1 K. e( i. `7 c) H
var Diffms = Tday[key].getTime() - time.getTime()
9 A G* B: s3 k/ U/ n4 N; t" V4 a DifferHour = Math.floor(Diffms / daysms)- Y; P% G1 V* U9 ]# R
Diffms -= DifferHour * daysms
% |* ]7 Z0 I; o0 @8 P1 q9 _ DifferMinute = Math.floor(Diffms / hoursms)/ k- s+ v& V0 n. y& B
Diffms -= DifferMinute * hoursms0 F% R. o, Z0 C; \9 D# F
DifferSecond = Math.floor(Diffms / Secondms)
1 d; `1 {0 F) G Diffms -= DifferSecond * Secondms' {# y4 X# s& P, G1 E0 J
var dSecs = Math.floor(Diffms / microsecond)& C- ]; s, [3 F- n0 z2 K
8 Z! w( c$ ~; o; z1 I2 g if(convertHour != DifferHour) a="<font color=red>"+DifferHour+"</font>天";/ b% p/ e9 T% S
if(convertMinute != DifferMinute) b="<font color=red>"+DifferMinute+"</font>时";
9 T1 ]* ?" Z2 L; g. Y1 G! n if(convertSecond != DifferSecond) c="<font color=red>"+DifferSecond+"</font>分"& Q# a( ]) N1 X$ b! T1 I
d="<font color=red>"+dSecs+"</font>秒"
# A. l$ K6 c/ P7 \ if (DifferHour>0) {a=a}
7 `. n8 i/ G. |$ `, N; o else {a=''}; T8 K& x, K; Q- i! p) z* D2 u
document.getElementById("leftTime"+key).innerHTML = a + b + c + d; //显示倒计时信息6 F) P+ ^ z; w
: p8 P! L% {% M6 ? }$ t5 p: V3 v u/ t) F+ w
</script>
3 z+ w* c3 c0 H& x<div id="sales" class="f_l clearfix">
$ `+ U8 A5 }8 w2 `3 V6 L! V B6 i <h1><a href="../search.php?intro=promotion"><img src="images/more.gif" /></a></h1>
# v- x# |2 X) D- a( }, F <div class="clearfix goodBox">
9 t+ K% M) V- X- S( A. B8 e6 \1 T <!--{foreach from=$promotion_goods key=key item=goods name="promotion_foreach"}-->) S9 H6 U( R2 Z; x4 _
{if $smarty.foreach.promotion_foreach.index <= 3}4 i$ J7 J3 L* T* s7 y; V
<div class="goodList">
. D( f, W- }( L6 v3 ^* l1 ` <a href="{$goods.url}"><img src="{$goods.thumb}" border="0" alt="{$goods.name|escape:html}"/></a><br />/ n/ c1 J7 z$ T1 T: j# x
<p><a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.short_name|escape:html}</a></p>( A( ?5 S3 t" n, b" e
{$lang.promote_price}<font class="f1">{$goods.promote_price}</font><br><font class="f4" id="leftTime{$key}">{$lang.please_waiting}</font>
( Q G" R, p9 L0 u8 a/ t' E/ v </div>
, C2 W% r4 ^" Z; Z: F) s# o6 U {/if}- {* x6 B( Z+ g3 ^/ G
<script>+ V4 F! e% \! k4 J
Tday[{$key}] = new Date("{$goods.gmt_end_time}"); 3 r% ]$ l3 _1 \- }6 n/ t2 _( t, {# r
window.setInterval(function() ! g1 F2 x& `& y, b! N4 T
{clock({$key});}, 1000); 1 ?5 p1 u* _5 H5 K, s
</script>5 F, O( g! z$ I5 M; G/ r
<!--{/foreach}-->% I$ G1 ?3 Y5 u2 K! P+ A
</div>
) z6 ^6 {) x0 K: q& Z </div>
- w7 q* Z( ?# ?7 b1 o
j( T& i( a( G+ C7 F<!-- {/if} --> |
1 k9 w `# T' R# s. w( ?+ y6 r* P2 O$ l
以上方法是在官方默认模板下实现的,如果你的是其他模板,有选择的把里面的一些代码挑出来增加(或修改)到你的recommend_promotion.lbi里即可。' @0 O, Y( Z5 I0 B! {! h* r
如果实现不了,可以QQ联系管理员# E- d0 V, q8 F% d
|