<?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