2010-06-02 126 views
0

我有这样的代码捕获日期和时间:显示不同的模板

date('F j, Y, g:i a T') 

,并保存作为

$datetime: 

,我有这样的代码包括模板:

function template_contents($file, $model) { 
    if (!is_file($file)) { 
     throw new Exception("Template not found"); 
    } 
    ob_start(); 
    include $file; 
    $contents2 = ob_get_contents(); 
    ob_end_clean(); 

    return $contents; 
} 

if($datetime == "No Date Yet"){ 
    echo template_contents("post.php", $model); 
} elseif($datetime == "June 2, 2010, 2:55 pm MDT"){ 
    echo template_contents("notpost.php", $model); 
}else { 
    echo template_contents("post.php", $model); 
} 

我的希望编辑ELSEIF语句显示notpost.php模板,如果在$日期时间小于 2天。所以,notpost.php显示两天,post.php显示两天后。

+0

这是一个自动过程,你的控制日期是硬编码? – Zuul 2010-06-02 22:07:10

回答

1

更改ELSEIF声明:

} elseif (time() <= strtotime("June 2, 2010, 2:55 pm MDT")) { 

这notpost.php显示,如果当前时间(由time()给出)比规定时间早。

+0

工作很好。谢谢! – Jon 2010-06-03 02:46:39