2013-02-18 94 views
0

我有一個包含標題(菜單導航和徽標)的PHP網站。
我在我的網站中有一個欄目,我想要添加一個不同的標題
我正在爲此付出努力。任何幫助,將不勝感激!
這裏是我的代碼:
PHP省略包含特定頁面

<div id="wrapper"> 
    <? include('inc/header.inc.php'); ?> 
     <? require('process/build_page.php'); ?> 
     <? require('inc/footer.inc.php'); ?> 

    </div> 

我想包括在名爲「我的關聯」的特定部分下面的頭

<? include('inc/header_ma.inc.php'); ?> 

過程/ build_page代碼如下所示:

<? 
global $full_uri; 

class BuildPage 
{ 

    function BuildPage() 
    { 
     global $full_uri; 

     if($full_uri) 
     { 
      $this->build_path(); 
     } 
     else 
     { 
      exit(); 
     } 
    } 

    function build_path() 
    { 
     global $full_uri; 

     $uri_array = explode("/", $full_uri); # make uri into an array divided by/
     $clean_uri = array_filter($uri_array); # remove empty elements 
     unset($clean_uri[1]); # remove base part of uri 
     $clean_uri = array_values($clean_uri); #reset array key to start with 0 

     # if array is empty the homepage is being requested 
     if(empty($clean_uri)){ 
      $clean_uri[0] = 'home'; 
     } 

     # build uri to point to include file 
     $new_path = "content/"; 
     $new_path .= implode("/", $clean_uri); 
     $new_path .= ".inc.php"; 

     $this->build($new_path); 

    } 

    function build($path) 
    { 
     $output = ""; 
     $output .= $this->get_include_contents($path); 
     echo $output; 
    } 
    function get_include_contents($filename) 
    { 
     if (is_file($filename)) 
     { 
      ob_start(); 
      include $filename; 
      $contents = ob_get_contents(); 
      ob_end_clean(); 
      return $contents; 
     } 
     return false; 
    } 

    function print_array($data) 
    { 
     echo "<pre>"; 
     print_r($data); 
     echo "</pre>"; 
     die(); 
    } 

}; 

$buildpage = new BuildPage(); 

?> 

請指教! 謝謝

回答

0

請讓我知道,如果我錯過了什麼,但不會這樣做的伎倆?

<div id="wrapper"> 
    <? 
    $change_header = array('/special_page_1','/special_page_2','/special_page_3'); 

    if(in_array($full_uri,$change_header)) 
     include('inc/header_ma.inc.php'); 
    else 
     include('inc/header.inc.php'); 
    ?> 
     <? require('process/build_page.php'); ?> 
     <? require('inc/footer.inc.php'); ?> 

</div> 
+0

我也試過類似的東西。但是你的和我的代碼都沒有工作。 – jes 2013-02-18 16:57:25