您可以向 url 添加一个参数来确定您所在的页面。
<?php
// at the top of the page
$quarters = array('Q1', 'Q2', 'Q3', 'Q4');
$quarter = 'Q1';
// don't allow access to any file on your system
if( isset($_GET['quarter']) && in_array($_GET['quarter'], $quarters) ) {
$quarter = $_GET['quarter'];
}
// switch the short syntax to a filename
switch($quarter) {
case 'Q1' :
$quarter = 'firstq.php';
break;
case 'Q2' :
$quarter = 'secondq.php';
break;
case 'Q3' :
$quarter = 'thirdq.php';
break;
case 'Q4' :
$quarter = 'fourthq.php';
break;
}
然后在您准备包含它的页面中。
<?php include_once $quarter; ?>
您到每个季度的链接将如下所示。
<ul id="quarters">
<li><a href="index.php?quarter=Q1"><img src="images/Q1.jpg" /></a></li>
<li><a href="index.php?quarter=Q2"><img src="images/Q2.jpg" /></a></li>
<li><a href="index.php?quarter=Q3"><img src="images/Q3.jpg" /></a></li>
<li><a href="index.php?quarter=Q4"><img src="images/Q4.jpg" /></a></li>
</ul>