[英]How can I incorporate inline CSS styles and stylesheets relating to one page only when using the PHP 'header'?
I have a 'header.php' file and I am incorporating it into my html pages using the following code: 我有一个“ header.php”文件,并使用以下代码将其合并到我的html页面中:
<?php /*
$pageTitle = "Home";
$section = "Home";
include('inc/header.php');
?>
The PHP header file contains a number of CSS stylesheets. PHP头文件包含许多CSS样式表。 Some of these CSS stylesheets I only want to include on one page - eg I only want to include 'index.css' on the page 'index.php'.
其中一些CSS样式表我只想包含在一页上-例如,我只想在“ index.php”页面上包含“ index.css”。 How can I include these stylesheets when I am using the same 'header.php' file in every page of the site?
当我在网站的每个页面中使用相同的“ header.php”文件时,如何包含这些样式表?
Is there a way of specifying these styles in the individual pages themselves, rather than in the header file? 有没有一种方法可以在各个页面中而不是在头文件中指定这些样式? If so, can these styles be placed in another element, even if the element has already been used (opened and closed) in the header file?
如果是这样,即使已在头文件中使用(打开和关闭)该元素,也可以将这些样式放置在另一个元素中吗?
Here is the code for my 'header.php' file: 这是我的“ header.php”文件的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title><?php echo $pageTitle ?> || Young Academy </title>
<meta name="description" content="Based in Pinner in North-West London, the Young Academy has been creating the highest standard of musical and dramatic education for 30 years.">
<meta name="keywords" content="Piano, Flute, Music Theory, Singing, Violin, Concerts, Pinner, Middlesex, Harrow, Teacher">
<meta name="author" content="Barbara Young">
<!--Stylesheets!-->
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css"/>
<link rel="stylesheet" type="text/css" media="all" href="css/text.css" />
<link rel="stylesheet" type="text/css" media="all" href="css/960_16_col.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/style.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="css/contact.css"/>
<!--Google fonts!-->
<link rel="stylesheet" type="text/css" media="all" href="http://fonts.googleapis.com/css?family=Quicksand:400,700">
<link href='http://fonts.googleapis.com/css?family=Titillium+Web' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Noto+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Karla:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Marck+Script' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700,500,500italic,400italic' rel='stylesheet' type='text/css'>
**<link rel="stylesheet" type="text/css" media="screen" href="css/index.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="css/bgaudioplayer.css"/>**
<!--Meta tags!-->
<meta name="author" content="Robert Young" />
<meta name="copyright" content="2013 by Robert Young" />
<meta name="keywords" content="Music lessons, Pinner, music tuition, piano lessons, speech and drama, London" />
<meta name="description" content="Site of the Young Academy, a private music tuition business based in Pinner" />
<script src="../js/modernizr.custom.63826.js"></script>
<script src="../js/html5shiv.js"></script>
</head>
<body>
<div class="header">
<div class="container_16 clearfix">
<ul class="nav grid_16 alpha">
<li><a class="<?php if ($section == "Home") {echo "here"; } ?>" href="index.php" accesskey="1"> Home </a></li>
<li><a class="<?php if ($section == "About Us") {echo "here"; } ?>" href="about_us.php" accesskey="2"> About </a></li>
<li><a class="<?php if ($section == "What We Do") {echo "here"; } ?>" href="what_we_do.php" accesskey="3"> What We Do </a></li>
<li><a class="<?php if ($section == "Enrolement") {echo "here" ; } ?>" href="enrolement.php" accesskey="4"> Enrolement </a></li>
<li><a class="<?php if ($section == "Contact Us") {echo "here" ; } ?>" href="contact.php" accesskey="5"> Contact Us </a></li>
<!--<li><a href="http://youngacademyblog.blogspot.co.uk/" accesskey="6"> Blog </a></li>-->
</ul>
<div id="logo">
<a href="index.php"><img src="img/Logo original.gif" alt="The Young Academy"/></a>
</div>
<div class = "grid_4 alpha">
<div class="telephone grid_4 alpha">
<img src="img/phone_icon_white.png" alt="small telephone logo" class="align-left small" />
<p> +44 (0)20 8866 3813 </P>
</div>
<div class="timezone">
<p><?php
date_default_timezone_set('Europe/London');
mktime(0,0,0,1,1,1970);
echo date('l, d F Y');
?> </p>
<!--<form action="http://www.example.com/login.php">
<p>
<input type="text name=search" size="20+" id="search" value="Search this site"
</p>
</form>!-->
</div>
</div>
<ul class="secondmenu grid_6 push_3">
<li><a class="<?php if ($section == "Musical Glossary") {echo "here" ; } ?>" href="glossary.php">Musical Glossary </a></li>
<li><a class="<?php if ($section == "FAQ") {echo "here" ; } ?>" href="faq.php">FAQ</a></li>
<ul>
</div>
I want to include the stylesheets in bold only on the index.php page. 我只想在index.php页面上以粗体显示样式表。 Can I include them like this:
我可以这样包括他们吗:
<?php
include('inc/header.php');
?>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="css/index.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="css/bgaudioplayer.css"/>
</head>
<article class="content">
<p class="grid_9 alpha"><i>Outstanding vocal and instrumental tuition.</i></p>
</article>
<article class="second-content">
<p class="grid_6 alpha omega">Develop a passion for music.</p>
</article>
<article class="third-content">
<p class="grid_5 alpha omega">Become a virtuoso.</p>
</article>
etc. 等等
Any help would be much appreciated! 任何帮助将非常感激!
Thanks, 谢谢,
Robert. 罗伯特
I have just tried the above code and it happens to work! 我刚刚尝试了上面的代码,它碰巧起作用了! You can include head tags in both the header.php file and the main (index.php) site file.
您可以在header.php文件和主(index.php)站点文件中都包含head标签。
Cheers! 干杯!
long story short you need some sort of router. 长话短说,您需要某种路由器。 but Looking at your code it seems like you may not have a firm grasp on Object Oriented Programming.
但是看一下您的代码,似乎您可能对面向对象编程没有足够的了解。 what you can do though is look at the URI with $_SERVER['REQUEST_URI'] if the string is lets say /about then load in resources for about-stylesheet.css.
但是,您可以执行的操作是使用$ _SERVER ['REQUEST_URI']查看URI(如果该字符串是说/ about),然后为about-stylesheet.css加载资源。
You can do this with an if else statement that replaces the link to your CSS and refers to the unique variable you sent for the page you want to pull the CSS in for: 您可以使用if else语句来替换CSS的链接,并引用您为要为其插入CSS的页面发送的唯一变量:
<link rel="stylesheet" type="text/css" media="screen" href="
<?php
if ($pageTitle == "Home") {
echo "css/index.css";
else ($pageTitle == "SomeOtherTitle") {
echo "css/relativelnk.css";
}
?>
"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.