Viridi Posted October 14, 2012 Share Posted October 14, 2012 Hi guys, I'm carefully trying to make my first website using php in college classes. Anyway, I'm using the normal include ('header.php') in my index.php file but when I add the the following code; <link rel="stylesheet" type="text/css" href="mystyle.css"> in index.php it will only apply to the content in index.php, not whatever is in header.php Do I have to add the code in header.php and footer.php too? I'd think there has to be an easier way, cause if I take any random Wordpress template as an example it never has that code in index.php, header.php AND footer.php. Help would be much appreciated, I wish I had the time to just study the book properly. Link to comment Share on other sites More sharing options...
HartleySan Posted October 14, 2012 Share Posted October 14, 2012 Viridi, I am a bit confused by what you said, but here are the basics: - Any files included by a PHP script become a part of that parent PHP script. In essence, you can imagine all the code in the included file being dropped in the parent PHP script at the exact point the file is included. - An external CSS file linked to as you have illustrated above will be applied to that entire one page. Thus, to efficiently apply the same CSS file to all pages on a site: - Link to a CSS file in the header file that you are including in other pages. - Include that header file in all your PHP pages. By doing so, you only have to write the header code once, and as long as you include that header file in every parent PHP page, the same CSS file will be applied to every page and you will have a consistent header on all pages. Furthermore, editing that header is simple, as you only need to edit one file to apply the changes to every page on the site. 1 Link to comment Share on other sites More sharing options...
Viridi Posted October 15, 2012 Author Share Posted October 15, 2012 Hi HartleySan, Thanks for your response and sorry for the confusion. I did indeed had to link the CSS file in header.php, I always thought it had to be in index.php. Luckily, that was my only issue. My site is working out pretty well now. Thanks again! Link to comment Share on other sites More sharing options...
HartleySan Posted October 15, 2012 Share Posted October 15, 2012 Good to hear. Thanks for letting us know. Link to comment Share on other sites More sharing options...
Recommended Posts