Re: including CSS & JS on only pages that need that CSS & JS [message #175576 is a reply to message #175565] |
Sun, 09 October 2011 20:31 |
Michael Joel
Messages: 42 Registered: October 2011
Karma:
|
Member |
|
|
On Sat, 8 Oct 2011 23:51:10 -0700 (PDT), paris2venice
<paris2venice(at)gmail(dot)com> wrote:
> I'm still a newbie at PHP. What would be the right way to include CSS
> and Javascript such that I could add CSS and JS just for those pages
> that need it?
>
> Would it be something like this? Is this how you do it?
>
> <?
> php require_once './css.php'; /* css.php contains
> doctype, meta & css needed universally */
> ?>
>
> <!-- link href= calls to CSS needed on local page only -->
>
> <?
> php require_once './js.php'; /* js.php contains
> javascript calls needed universally */
> ?>
>
> <!-- script type="text/javascript" calls to Javascript needed on
> local page only -->
> </head>
>
>
> Thanks a bunch for your help.
I think you are meaning you want to use PHP includes to drop in your
css and javascript. You can use the normal method combines with PHP or
just PHP...
Combined methode:
<link rel="stylesheet" type="text/css" href="GlobalCSS.css" />
<script type="text/javascript" src="GlobalJavascript.js"></script>
<?php
if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
include("StylesForThisSpecialPage.php");
include("StylesForThisSpecialPage.php");
}
?>
The other method:
<?php
include("GlobalCSS.php");
include("Globalavascript.php");
if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
include("StylesForThisSpecialPage.php");
include("SpecialJavascript.php");
}
?>
Of course the PHP files must be written just as they would be if they
were coded directly on the HTML page (not as if they are being
"linked").
Right or wrong? It works.
Mike
|
|
|