2011-03-18 86 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> 

这种方式只能加载给定页面所需的内容。