I have been having this issue when I use the php include() or require() function. I will try and explain it as best as possible down here but let me know if it does not make sense. I am building a theme system where the main index.php has include ('themes/main/header.php') but there are errors when linking stylesheets and images. Here is how my directory is set out.
- htdocs
- index.php
- themes
-
- main
-
-
- header.php
-
-
-
- footer.php
-
-
-
- images
-
-
-
- css
-
-
-
- js
-
Here is the contents of my header.php (striped):
<html>
<head>
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
</head>
<body>
<div class="header">
<img src="images/logo.png" />
</div>
When I load up the main index.php the stylesheet and images are not able to be found. I know this is because the header file is brought into the index.php file but is there a way around this? Thank you so much.
I, for myself, use something like this:
in short, this builds a “site absolute” path for you, this way you could also change the name of your “theme” without having to change all absolute references it contains.
this way, in
header.phpyou can write:the function has several optional attributes, they should be self explanatory.