原谅我,因为我在网络开发方面仍然是个新人。 :)
通常当我创建我的网站时,我创建了一个名为header.html和footer.html的文件,只是将这些文件包含在我的网页中以保持一致,这样我只需要更改数据一次,然后添加任何必要的代码。 (例如:index.php)
<?php
include ('includes/header.html');
include ('html/index.html');
include ('includes/footer.html');
//other php codes
?>
现在我的问题是在我的一个页面上(food-menu.php),我有一个侧边栏,我已经设置了链接,根据点击的链接检索页面 - 以及我的代码我目前正在检索动态内容。我唯一的问题是如何在该页面变为动态之前设置默认内容?
侧边栏是这样的:
//Sidebar
<section class="widget">
<h3 class="title">Main Menu</h3>
<ul>
<li><a href="?link=1" name="link1" title="View all Cold Starters">Cold Starters</a></li>
<li><a href="?link=2" name="link2" title="View all Hot Starters">Hot Starters</a></li>
<li><a href="?link=3" name="link3" title="View all Charcoal Grilled">Charcoal Grilled</a></li>
<li><a href="?link=4" name="link4" title="View all Chef's Special">Chef's Special</a></li>
</ul>
</section>
然后主文件是(food-menu.php :)
<?php
include ('includes/header.html');
$link = $_GET['link'];
if ($link == '1'){
include 'html/cold-starters.html';
}
if ($link == '2'){
include 'html/hot-starters.html';
}
if ($link == '3'){
include 'charcoal-grilled.html';
}
if ($link == '4'){
include 'chef-special.html';
}
include ('includes/menufooter.html');
?>
检索文件有效,但我如何设置默认包含页面?比如设置('html / cold-starters')成为第一页,当他们去food-menu.php网址时?因为到目前为止我只包括页眉和页脚,但不包括默认内容页面。
谢谢专家! :)
答案 0 :(得分:1)
您可以通过以下方式修改代码:
$link = isset($_GET['link']) ? $_GET['link'] : 1;
这里发生的是,如果您已经给出了链接参数,则需要它,否则它将采用默认值1
。