To get it to work from any directory you could use the fully qualified URL When you include a file you always work with the location of the parent file
<!DOCTYPE html> <html> <head> <title>This is a title</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body> All of you content. </body>
When ./work/index.php includes ./header.php the browser reads the relative link of the CSS file (./css/style.css) and assumes the CSS file is relative to ./work/index.php and therefore looks for it at ./work/css/style.css.
As @karlpcrowley said your link in header.php should have the full url so that it can be found from anywhere on your site.
Schmotty is spot on, but if you're going to be doing this a lot you are better off having a settings file and defining the absolute url This would make a difference on large sites
As I'm currently running on a local server, including a full url wouldn't work but once I finish development, I suppose I could go in and manually add in the full url.
But how would I go about making a settings file to define the absolute URL?
And as note, I know nothing about PHP, just how to work includes thats just because of wordpress development.
Doing this is handy for other things like database credentials and some people even go as far as to specify maintenance mode in here as a Boolean value
This is my directory:
index.php
header.php
footer.php
css/style.css
work/index.php
now the work/index.php i've figured out how to include the header which contains the css file links.
The problem is, the css won't load from that work/index.php file.
What do I need to add the to header.php file to get the css files to load no matter which directory a php file is calling it from?
When you include a file you always work with the location of the parent file
As @karlpcrowley said your link in header.php should have the full url so that it can be found from anywhere on your site.
or if you need php for changing hosts
This would make a difference on large sites
But how would I go about making a settings file to define the absolute URL?
And as note, I know nothing about PHP, just how to work includes thats just because of wordpress development.
Any help would be appreciated.
then do something like this
settings.php
your page
Doing this is handy for other things like database credentials and some people even go as far as to specify maintenance mode in here as a Boolean value