Jump to content

Missing something basic using the includes statement and linking css / js files to my php page.


skygremlin

Recommended Posts

I’m trying to organize a site and am missing something basic with linking my css..  Right now all the pages are in the root folder.  I am using a template that  includes a header and footer, only changing the body on each page.  The header file contains links to the css and js files.


 


I want to move all my news and events to a sub folder (newsEvents), as I expect a large number of these pages. 


 


For example:


Folder structure:


  • root/css/main.css
  • root/includes/header.php
  • root/newsEvents.php 
  • root/newsEvents/2014-04-29_eventPosting.php

 


Working Page: 


  • root/newsEvents.php  —  loads css and javascript fine
    • Inside of this page is the below line
    • include(includes/header.php);

 


Not working Page: 


  • root/newsEvents/2014-04-29_eventPosting.php  —  Does not load the css or the javascript
    • Inside of this page is the below line
    • include(../includes/header.php);

  


 


I’m looking at the Debugger in FF, and I’ll see the CSS file listed for each page, but it shows 0 rules on the one not working.  On the working page it shows 198 rules.  I thought changing the includes path would be enough to load the header, which would included path’s to the css and js files..   But again, I’m missing something basic..


 


I’m using MAMP for my testing.  If that makes a difference..  


 


thank you 


Link to comment
Share on other sites

I've also tried this with same result....

$docRoot = ($_SERVER['DOCUMENT_ROOT']);
	echo'<script type="text/javascript">window.alert("Doc Root:  '.$docRoot.'")</script>';
	$headerLink = ($docRoot . "/css/header.php");
	echo'<script type="text/javascript">window.alert("Another Link to Header:  '.$headerLink.'")</script>';

include($headerLink);

I think it's something more fundamental that I'm missing......  

Link to comment
Share on other sites

Folder structure with some additional data:


  • root/css/main.css
    • Inside the css file


      • .header-news-events { background-image: url("../img/sub-img/sub-news.jpg"); }




  • root/img/sub-img
  • root/includes/header.php
    • ​Inside the Header File


      • <link rel="stylesheet" href="css/main.css">
        <script type="text/javascript" src="js/main.js"></script>




  • root/js/
Link to comment
Share on other sites

I want to move all my news and events to a sub folder (newsEvents), as I expect a large number of these pages.

 

 

that's a sign you need to store the content in a database and dynamically output it using ONE page. by producing a large number of php files that only vary in the content they contain, you are just making a lot of make-work for yourself producing and managing the files. the the computer do this work for you.

 


 

as to your problem. the php include statement essentially replaces the include() statement with the content of the file being included. it doesn't matter where the file being included is stored at, it could be twenty folders deep in your site or even below/outside your document root folder, any links in the resulting web page are relative to the main file.

Link to comment
Share on other sites

Thanx mac_gyver.  I thought about putting the full page content in the DB and using one page file for display, but wasn't sure if putting html in the DB was the right path to take.  Sounds like in this instance not a bad choice.  

 

 

thank you 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.