May 31

剛剛我發現我這裡的 calendar 已經跳到 6 月, 像這樣 :
WP Calendar error

於是去看了 , 也都有這個問題.

看過程式之後, 果然是 gmt_offset 所產生的問題.

因為在 wp-includes/functions.php 中的 current_time 這個 function 提供了兩種格式: mysql 跟 timestamp .
而 mysql 的格式用了 gmdate , 所以加上 gmt_offset 之後是沒問題的.
timestamp 卻因為使用了 time , 所以再加上 gmt_offset 之後會出現異常.
因為我發現只有 calendar 出問題, 所以我只改了 wp-includes/template-functions-general.php 這個檔案, 沒有修改 current_time 這個 function .

如果您的站台的 calendar 也有相同問題的話, 請修改 wp-includes/template-functions-general.php , 把原先這兩行註解掉:

$thisyear = gmdate("Y", current_time("timestamp") + get_settings("gmt_offset") * 3600);
$thismonth = gmdate("m", current_time("timestamp") + get_settings("gmt_offset") * 3600);

加進這兩行 :

$thisyear = gmdate("Y", current_time("timestamp"));
$thismonth = gmdate("m", current_time("timestamp"));

也就是變成這樣 :

//        $thisyear = gmdate("Y", current_time("timestamp") + get_settings("gmt_offset") * 3600);
//        $thismonth = gmdate("m", current_time("timestamp") + get_settings("gmt_offset") * 3600);
$thisyear = gmdate("Y", current_time("timestamp"));
$thismonth = gmdate("m", current_time("timestamp"));

如果您有 shell login 權限的話, 可以到您的 WordPress 主目錄, 然後抓取 這個檔案 後用這個指令做修正 :

patch < template-functions-general.diff.txt

Technorati Tags: ,

Related posts:

Tags: ,
(Visited 6345 times)

5 Responses to “WordPress 的小日曆 bug”

  1. shakalaca Says:

    XD 之前修正過想說 5/31 看效果, 沒想到 svn 之後就蓋過去了 .. orz


    From Taiwan Taiwan
    Using Mozilla Firefox Mozilla Firefox 1.0.4 on Windows Windows XP
  2. JoeHorn Says:

    自己改過的要記得留一份 diff file 啊... XD
    ( 然後順便 share 出來!? :cool: )


    From Taiwan Taiwan
    Using Mozilla Firefox Mozilla Firefox 1.0.4 on Windows Windows XP
  3. 孙秀楠宝宝网站 » Blog Archive » links for 2005-12-10 Says:

    [...] Joe Horn 的啟示錄 » WordPress 的小日曆 bug [...]


    From United States United States
    Using WordPress WordPress 1.5.2
  4. 心如止水 | WordPress的日历Bug Says:

    [...] 于是上网搜索。的确,WordPress中存在着日历的Bug。Joe Horn说,是由于 gmt_offset 所产生的问题。


    From China China
    Using WordPress WordPress 2.0.2
  5. IE Vulnerability Says:

    New Internet Explorer Vulnerability that can't be fixed...

    [...]talked about vulnerabilities in Microsoft[...]...


    From United States United States
    Using Opera Opera 9.64 on Windows Windows XP