<?php
date_default_timezone_set('Europe/London');
$hour = (int) date('H');
if (($hour > 8 && $hour < 18)) {
// it's past 8 AM and less then 6 PM
$daytime_design = true;
$resource_path = 'day';
}
else {
// the other hours, 6 PM to 8 AM the next day
$daytime_design = false;
$resource_path = 'night';
}
?>
我们template.tpl.php或任何很久以后
<!doctype html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="/css/<?=$resource_path;?>/style.css">
</head>
<body>
<?php
if ($daytime_design === true) {
echo 'Good Day!';
}
if ($daytime_design === false) {
echo 'Only shows for night design, <img src="special-night-image.jpg">';
}
?>
This will show /images/day/logo.jpg or /images/night/logo.jpg
<img src="/images/<?=$resource_path;?>/logo.jpg">
</body>
</html>
在页面顶部的链接中输出不同的样式表网址。使这个样式表“黑暗”。 –
你不确定如何拥有两种不同的设计或如何在不同的时间显示不同的设计? – bendataclear
是的,它可以这样做,每当页面加载它将要切换模板 – 2012-10-31 14:57:48