0

I downloaded a Template + CSS File for a Website that I'm Building, the template worked well until I tried to break it down and put every code in its own file (for easy modification and editing in the future). So, when I cut the head part which included (Title + Meta Data .. etc ), and put it in its own file, and replaced it (for sure) with an include() function, I lost the CSS styles and returned to the basic & standard style (Black & white with no extra format .. etc)

Where did I Go wrong? Knowing that here is the include function that I've used:

<?php
include 'files/head.php';
?>
9
  • Open developer tools or firebug and see if code defined in head is loaded at all. Also - you may add error_reporting(E_ALL) at the beginning of your script and see if some errors are shown. Possibly include path is simply wrong. Commented Apr 2, 2013 at 7:56
  • You are not including the part where css file link is. Commented Apr 2, 2013 at 7:58
  • If the title and other meta data is being shown the problem will be due to relative paths for the CSS. Try setting the full-path to the CSS to see if that helps resolve it for now e.g. mysite.com/files/style.css Commented Apr 2, 2013 at 8:04
  • my css file is in : C:\xampp\htdocs\test6\css\screen.css my head file is in : C:\xampp\htdocs\test6\files\head.php what should the path to css file be ? ( the INDEX is in : C:\xampp\htdocs\test6\index.php ) Commented Apr 2, 2013 at 8:19
  • It depends. What is an url when you open index.php? localhost/index.php or localhost/test6/index.php? Or maybe some other url? Commented Apr 2, 2013 at 8:27

1 Answer 1

1

With an URL like file:///C:/xampp/htdocs/test6/index.php PHP is NOT executed. You must run it with apache being involved. Currently you are opening your PHP script as a regular txt or html file - it is just passed to browser without processing.

In order to make include function work you must run it with apache. As you are using xamp, I think you should simply open it with URL like http://localhost/test6/index.php In this case, apache will get that request and pass it to PHP. PHP engine will interpret your PHP script and "replace" include files/head.php with a content of head.php. If everything is Ok, after pressing Ctrl+U (or looking at HTML with Developer Tools or Firebug) you should see a content of head.php instead of <?php include ....

Please note that css files should be linked with relative URL like css/screen.css. Or absolute URL like http://localhost/test6/css/screen.css. like Search for relative and absolute URLs in google for more info.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.