2014-09-24 40 views
0

我試圖做出導航菜單。我在我的index.php文件中使用代碼「include」使用他的菜單文件。導航菜單回到目錄嘗試時,Href不起作用?

當我選擇吉他的作品。但是當重新按下主頁按鈕時。不能回到索引或家庭?吉他.php文件在direcorty網頁/吉他.php。

爲什麼這不能直接返回索引?請幫幫我。謝謝

<ul> 
 
<li><a href="index.php" >Home</a></li> 
 
\t \t \t <li><a href="pages/guitar.php">Guitars</a> 
 
\t \t \t \t \t <ul> 
 
\t \t \t \t \t <li><a href="#">Guitar Acoustics</a></li> 
 
\t \t \t \t \t <li><a href="#">Guitar Electirs</a></li> 
 
        <li><a href="#">Guitar Amplifiers</a></li> 
 
\t \t \t \t \t <li><a href="#">Guitar Effects</a></li> 
 
\t \t \t \t \t 
 
\t \t \t \t </ul> 
 
\t \t \t 
 
\t \t \t </ul>

以上是在文件導航菜單中的代碼。上述

<?php 
 
require_once "layout/header.php"; 
 
include ("layout/nav.php"); 
 
require_once "layout/aside.php";?> 
 
?>

是在文件的index.php代碼,和頁/ guitar.php。 謝謝...

回答

0

您的鏈接是相對的,這意味着它們只會替換URL末尾的「xxx.php」位,因此當您轉到「pages/guitar.php」時,您的主鏈接成爲「pages/index.php」。

使它們以/開頭,它們將與您的域相關,例如。如果您的網站是mydomain.com,那麼您的主頁將變爲mydomain.com/index.php,吉他頁面將變爲mydomain.com/pages/guitar.php

<a href="/index.php">Home</a> 
<a href="/pages/guitar.php">Guitars</a> 

如果您的網站不在您的網域的根目錄下,那麼網站會變得更加複雜。例如,如果你的網頁實際上是在mydomain.com/guitar-site/index.php,那麼你就需要將/guitar-site添加到URL的前一樣,所以鏈接出現在正確的地方:

<a href="/guitar-site/index.php">Home</a> 
<a href="/guitar-site/pages/guitar.php">Guitars</a> 
+0

謝謝你,在域名的根目錄下的問題。更改爲Home Guitars並正常工作:) – 2014-09-24 08:37:16

-1

嘗試用header("location:layout/nav.php");

更換 include ("layout/nav.php");
+1

這會將您重定向到'layout/nav.php'文件,並將其顯示爲不帶標題,旁邊和內容。你可能不希望這樣 – Joe 2014-09-24 08:19:01

相關問題