2011-04-11 106 views
0

任何人都可以建議如何改變每個頁面加載調用的模板,以在一個頁面上顯示特定的部分?一個文件,在一個頁面上顯示代碼,但在另一個頁面上排除代碼?

我希望我解釋得很好......

index.php includes;

require_once('./cache/templates/sidebar.php'); 

以後每頁面是內置使用了哪些內容的index.php文件中定義,這意味着的sidebar.php是必須的。

我想編輯sidebar.php以包含僅顯示在索引頁上的廣告。

目前,當我編輯sidebar.php時,例如顯示字母「B」時,它將顯示在主頁上,並且每隔一頁顯示如此;

索引頁:http://img.photobucket.com/albums/v684/nilsatis/1stack.jpg 所有其他網頁:http://img.photobucket.com/albums/v684/nilsatis/2stack.jpg

我怎麼能決定一個包含文件中的一個區域顯示在一個頁面上,但不包括顯示在別人呢?

編輯:非常感謝您的時間。真的很感激。

我繼承/購買的網站,我發現index.php文件非常氣質。

我試圖把這段代碼放在邊欄內(或在它下面,在頁腳上方),但是index.php上的任何修改都會將其解除。

 } 

     if (isset($url[1])) require_once('./cache/html/'.$url[0].'/'.$url[1].'.php'); 
     else require_once('./cache/html/'.$url[0].'.php'); 
    } 
} 
require_once('./cache/templates/sidebar.php'); 


} 


require_once('./cache/templates/footer.php'); 

回答

0

一個快速和骯髒的黑客將被插入index.php頁面上的自定義CSS樣式表使一些DIV這是的「的sidebar.php」部分可見。

實施例:

的sidebar.php:

<?php 
    echo '<div id="theLetterB" style="display:none">B</div>'; 
    ?> 

的index.php:

<?php 
    if ($_SERVER['PHP_SELF'] == 'index.php') // Replace this with something to differentiate between pages 
    { 
     echo '<style type="text/css"> #theLetterB { display:block; } </style>'; 
    } 
    ?> 
+0

由於利奧爾。我已添加更新。 – Dan 2011-04-12 18:02:27

相關問題