Getting stylesheets to work in header.php and files associated with it
Let's say I created a header.php file in my includes folder. And I include it in my index.php file in the site root directory.
Then in the header.php file, I have a link to the style sheet.
The issue I've always found is that you can't get the header.php file to apply the stylesheet.
I can get it to work using global links, however I don't want to do that as I'll have to undo them before I upload the site. (And I forget....)
So anyways, I came up with this code today in an attempt to overcome this. Here is my header file so far:
<!-- SETTING MY VARIABLES -->
<?php
$directory = getcwd()
?>
<?php
$currentFolder = strpos($directory, "includes");
?>
<!--END OF VARIABLES -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<!-- SCRIPT TO PROCESS STYLE SHEET -->
<?php
if($currentFolder !== false) {
echo "<link href=\"../styles/stylesheet.css\" rel=\"stylesheet\" type=\"text/css\" />";
} else
echo "<link href=\"styles/stylesheet.css\" rel=\"stylesheet\" type=\"text/css\" />";
?>
<!-- END OF SCRIPT FOR SYTLE SHEET -->
</head>
<body>
<div id="headerWrapper"></div>
So here is what it is doing:
1. It is creating a variable called $directory which is equal to the current directory.
2. Then it is creating another variable called $currentFolder which is equal to whether or not the variable $directory contains the word "includes".
3. Then it says if $currentFolder is NOT false then it has the location of the stylesheet in relation to the header.php file.
4. Else - if it IS false then the stylesheet is located in a location in relation to files in my root directory.
This works perfectly fine....in Live view. Both the header.php and index.php will format the header in live view. Neither though will format it in Design view. Which sucks cause I was pretty happy that I came up with this code on my own.
The reason it isn't working in Design View - I realize now - is because Dreamweaver won't process that script in Design View.
Does anyone know of a way to get this script to run in Design View? Or maybe some suggestions on editing this code to get it to work in Design View?
Thanks!
