我正在整理一个基于Wordpress的竞赛网站。法律上,比赛必须在午夜开始。为了避免在午夜起床来设置内容,我想构建一些PHP逻辑以在开始日期之后显示所有内容,然后再显示初始页面的一些基本HTML。我是TOTAL编程新手,但我正在尝试解决问题,这是到目前为止的内容:
<?php
// The current date
$date = date('Y, j, m');
// Static contest start date
$contestStart = ('2012, 02, 03');
// If current date is after contest start
if ($date > $contestStart) {
//contest content?
}
else {
// splash content?
}
?>
Run Code Online (Sandbox Code Playgroud)
我觉得有更聪明的方法可以做到这一点。我的网站很大...将整个内容包装在if语句中似乎很荒谬。也许完全基于日期重定向到另一个页面?
任何帮助表示赞赏。
您将需要修改WordPress主题,以便在整个站点范围内进行更改。
<?php
$date = time();
$contestStart = strtotime('2012-02-03 00:00:00');
if ($date < $contestStart) {
?>
<html>
Insert your whole splash page here.
</html>
<?php
exit;
}
?>
//The normal template code should be below here.
Run Code Online (Sandbox Code Playgroud)
完成后,不要忘记单击WordPress上的“更新文件”按钮;并像其他人一样,确保您指定的时间与服务器所在的时区同步。