2015-10-06 164 views
-2

嗨,大家好我正在爲一個學校項目做一個網站,但爲了保持有組織,我希望在一個文檔中包含所有頁面,並且當您訪問該網站時,默認頁面是索引。 PHP和其他頁面鏈接如下:index.php?p=page 現在的問題是,我有這個腳本,但不知道我在哪裏。我也不熟悉PHP,我從我的一個朋友那裏得到了它。它是這樣的:多個HTML頁面在一個文件

?> 
<php? some php code ?> 
<html tag etc> 
<head> Head stuff </head> 
<Nav> <Header> 
<php? some php code where I filled in what the link was of the content under   it ?> 
< The content of the page, excluding the header, navigator etc because that was above here. > 

?> 

Then I could do the same thing over and over again, and just change the PHP code and it worked. 

<footer stuff> 
</body> 
</html> 

我知道有很多這樣的腳本,我搜索谷歌超過一個小時,但沒有成功。

-Tristan

+0

你正在尋找的東西是這樣的:'如果(isset($ _ GET [ 'page'])&&($ _GET ['page'] =='something')' –

+0

' Barmar

+0

現在我該如何把它放到網站中?你給我一個完整的例子,因爲我是一個完整的PHP noob。 –

回答

0

A的工作原理非常簡單的例子:

<?php 

$page = $_GET['page']; 

if ($page == 'one') { 
    echo 'This is page one!'; 
} elseif ($page == 'two') { 
    echo 'This is page to'; 
} 

// http://yoursite.com/index.php?page=one 
// Outputs 'This is page one!' 

瞭解更多一點關於GET請求,就在這裏:$_GET

0

這將幫助你: Serve multiple pages from 1 PHP file?1

如果你想使像youtube.com/?watch=XXXXXXXXX 所以你只需要改變XXXXXXXXX顯示多個內容。

,但你仍然可以使用:

  1. 單頁的導航系統。
  2. 顯示/隱藏頁面隨着JS

例子的JavaScript:

我們WEBSITE1作爲一個網站

我們有一個 - B - C - d爲網頁

JS會隱藏所有頁面,以免除您要顯示的頁面。