skygremlin Posted April 29, 2014 Share Posted April 29, 2014 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 fineInside 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 javascriptInside 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 Quote Link to comment Share on other sites More sharing options...
adam_bray Posted April 29, 2014 Share Posted April 29, 2014 Are you using a "/" at the start of your include? Quote Link to comment Share on other sites More sharing options...
skygremlin Posted April 29, 2014 Author Share Posted April 29, 2014 Do you mean like this? include("/../includes/header.php"); If I do that I loose my header.. Quote Link to comment Share on other sites More sharing options...
skygremlin Posted April 29, 2014 Author Share Posted April 29, 2014 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...... Quote Link to comment Share on other sites More sharing options...
skygremlin Posted April 29, 2014 Author Share Posted April 29, 2014 I also have url linking in my css file to yet another folder location.. From the css file that's ../img/sub-img/... Could that be messing with something? I thought the url links started at the css file location though.. Quote Link to comment Share on other sites More sharing options...
adam_bray Posted April 29, 2014 Share Posted April 29, 2014 What's the URL to your CSS / JS files? Quote Link to comment Share on other sites More sharing options...
skygremlin Posted April 30, 2014 Author Share Posted April 30, 2014 Folder structure with some additional data: root/css/main.cssInside the css file .header-news-events { background-image: url("../img/sub-img/sub-news.jpg"); } root/img/sub-img root/includes/header.phpInside the Header File <link rel="stylesheet" href="css/main.css"> <script type="text/javascript" src="js/main.js"></script> root/js/ Quote Link to comment Share on other sites More sharing options...
adam_bray Posted April 30, 2014 Share Posted April 30, 2014 This should fix it - <link rel="stylesheet" href="/css/main.css" /> <script type="text/javascript" src="/js/main.js"></script> Quote Link to comment Share on other sites More sharing options...
skygremlin Posted April 30, 2014 Author Share Posted April 30, 2014 nah that didn't work, and that removes the css to my root/home.php... Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 30, 2014 Share Posted April 30, 2014 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. Quote Link to comment Share on other sites More sharing options...
skygremlin Posted May 2, 2014 Author Share Posted May 2, 2014 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 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 3, 2014 Share Posted May 3, 2014 the html layout of your web page shouldn't be stored in the database, only the content that goes on the web page. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.