为动态变化的内容网站设置默认页面


Setting a default page for a dynamic changing content website

原谅我,因为我在web开发方面仍然是新手。:)

通常,当我创建我的网站,我创建一个文件名为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/冷启动器')是第一页,当他们去的食物菜单。php url?因为到目前为止,我只包含了页眉和页脚,而没有包含默认的内容页。

谢谢专家!:)

你可以这样修改你的代码:

$link = isset($_GET['link']) ? $_GET['link'] : 1;

这里的情况是,如果你给了link参数,它会取它,否则,它会取默认值1