2011-12-24 2 views
0

나는 모든 파일에서 탐색 부분을 제거하고 별도의 파일 이름 nav.php에 보관하고선택한 항목에서 내비게이션 항목을 활성화하는 방법은 무엇입니까?

include ('includes/nav.php'); 
으로 필요한 장소를 불렀다

다음과 같이 nav.php 파일의 내용입니다 :

<ul> 
     <li<?php if ($thisPage=="http://www.finalyearondesk.com") 
      echo " class=\"selected\""; ?>> 
       <a href="http://www.finalyearondesk.com">Home</a></li> 

     <li<?php if ($thisPage=="http://www.finalyearondesk.com/contact.php") 
      echo " class=\"selected\""; ?>> 
       <a href="http://www.finalyearondesk.com/contact.php">Contact US</a></li> 

     <li<?php if ($thisPage=="http://www.finalyearondesk.com/downloads.php") 
      echo " class=\"selected\""; ?>> 
       <a href="http://www.finalyearondesk.com/downloads.php">Downloads</a></li> 
</ul> 

그러나 문제는 페이지를 방문 할 때 선택한 현재 항목을 가져올 수 없다는 것입니다. 코드가 잘못되었습니다.

+0

var $ thisPage는 무엇입니까? –

+0

표시해야하는 페이지가 3 개 있습니다. –

답변

0

를 할당하지 않기 때문에

include ('includes/nav.php'); 

당신은 할당되지 않은 회선 전에이 있어야한다 값을 $ thisPage로 변경하십시오. nav.php의 ul 앞에 다음 코드를 추가하십시오.

<?php 
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') 
       === FALSE ? 'http' : 'https'; 
$host  = $_SERVER['HTTP_HOST']; 
$script = $_SERVER['SCRIPT_NAME']; 

$thisPage = $protocol . '://' . $host . $script; 
?> 
+0

감사합니다. 효과가있었습니다. 이전에이 사실을 알지 못했습니다. –

0

확인, 당신은 $ thisPage에 전체 URL을 할당하고 당신의 niv.php 당신이 $ thisPage

관련 문제