2011-03-18 72 views
0

所以我把我的index.php頁面分成三部分:top,middle,bottom。中間部分將有不同的html php inlude頁面,因此需要不同的樣式表。我是否將單個php包含頁面中的特定樣式錶鏈接到索引頁面?因爲在索引頁面中,不同的樣式表似乎不起作用,爲什麼呢?如何鏈接不同的樣式表爲不同的php包含文件

+0

您應該將URL的樣式表放入一個變量中,以供模板引擎正確使用。 – 2011-03-18 02:56:48

+0

我想我的問題是,爲什麼中間部分php包含文件的樣式表在我將它們鏈接到index.php頁面時被識別? – dave 2011-03-18 02:58:16

+0

我們需要查看代碼來回答這個問題。 – 2011-03-18 03:02:59

回答

2

假設你about頁有需要,你可以做這樣的事情一個自定義的CSS文件:

about.php

<? 
$css = array('path_to_css_file', 'path_to_another_css_file'); 
require_once('header.php'); // aka the top 
?> 

[about page content goes here] 

<? 
require_once('footer.php'); // aka the bottom 
?> 

將在header.php文件,你可以這樣做:

header.php

<html> 
<head> 
<title></title> 
<link rel="stylesheet" type="text/css" href="main_style_sheet.css" /> 
<? 
if (isset($css) && is_array($css)) 
    foreach ($css as $path) 
    printf('<link rel="stylesheet" type="text/css" href="%s" />', $path); 
?> 
</head> 
<body> 

這種方式只能加載給定頁面所需的內容。

相關問題