0

The problem I'm having is that when I do changes to my css file. Only the index.php gets affected.

Code from the <head> in home.header.php

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="User." />
<meta name="keywords" content="User" />
<meta name="author" content="User" />
<meta name="copyright" content="2014, User" />
<meta name="expires" content="never" />
<title>Sitemap | your website</title>

<link rel="shortcut icon" type="image/ico" href="">
<link rel="stylesheet" href="./css/styles.css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>

I know it has something to do with locations being able to allow the other pages see.

Please view the screenshot provided.

file structure

All of the pages share the same head information, but the css is only applying to the index and not any of the other pages. In in photo I have a folder called sitemap, contact and etc. All of which include the page.header.php files.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
nickhiebertdev
  • 525
  • 1
  • 6
  • 21
  • Please provide some code. its difficult to help without ;-) Try an absolute link like `http://...` or `/css/...` – toesslab May 07 '14 at 17:05
  • `` remove the dot. – Funk Forty Niner May 07 '14 at 17:08
  • `./` means "current directory". `../` means "parent directory". `/` means "root directory". – h2ooooooo May 07 '14 at 17:11
  • 1
    That worked thank you, It's been awhile since I've touched structures and just needed a refresh. – nickhiebertdev May 07 '14 at 17:13
  • You can also use as an include `define("ABSPATH", dirname(__DIR__)."/"); include(ABSPATH.'/css/styles.css');` @nick.hiebert that way you won't have a bunch of files to edit, should you want to change something, or you happen to rename your CSS file. – Funk Forty Niner May 07 '14 at 17:21
  • You can use PHP inside your `` you know. – Funk Forty Niner May 07 '14 at 17:31
  • Thanks your're right. I'm going to simplify this process. Seems silly to have a ton of files with slightly different changes. I actually thought about storing variables for page names with the proper directory using a dirname. That way I can have just one header.php file. It'll be a good practice as well. I'm guessing it can be done the same as you provided above? – nickhiebertdev May 07 '14 at 19:27
  • Also for the nav.php files. Making it into just one. – nickhiebertdev May 07 '14 at 19:31
  • @Fred-ii- See my comments above. – nickhiebertdev May 07 '14 at 19:33
  • @nick.hiebert Yes, you can do pretty much anything you want to include etc. in PHP, just as long as the right code is inside the right tags. For example, you wouldn't place any HTML-related code inside `` but you can if it's related to those tags. Metatags/JS etc, CSS stuff like that. Will save a lot of trouble for sure. – Funk Forty Niner May 07 '14 at 19:36
  • @Fred-ii- Right now I'm trying to figure out how to add a certain set of nav ul for each page into variables. Then just call them when I require them onto whatever page I choose. – nickhiebertdev May 07 '14 at 19:44
  • @nick.hiebert Now that's a different topic that I'm not well-versed in. That will call for a `if($page==page1.php){...}` or something to the effect. I suggest you Google "php if current page include" and you're bound to get a lot of results. – Funk Forty Niner May 07 '14 at 19:47
  • @Fred-ii- I'm trying the first solution on this post: [link](http://stackoverflow.com/questions/17638165/get-ul-li-a-string-values-and-store-them-in-a-variable-or-array-php) But it doesn't appear to be working so far. – nickhiebertdev May 07 '14 at 19:51
  • I think I may not have fully understood what you asked. You mean like `$var = "
    • Option 1
    • Option 2
    ";` and then `echo $var;` type of thing? @nick.hiebert
    – Funk Forty Niner May 07 '14 at 19:56
  • That's exactly it, I'm exploring some options and see what works and what doesn't. – nickhiebertdev May 07 '14 at 19:59
  • Ok, well just be careful what you put in there, as far as quotes go and special codes you think you'd want to use. But in a nutshell, that's basically what you can do. @nick.hiebert what I put above is valid code. Plus, always add `. "\n"` at the end of all lines, it will make for nice clean code. I.e.: `$var = "
    • Option 1
    • Option 2
    " . "\n";` and will show up in HTML source all nicely aligned, instead of one long line, which many make that mistake.
    – Funk Forty Niner May 07 '14 at 20:02
  • Oh, and since you haven't accepted any answers below, let me know if you want to close the question and be marked as answered. I can use a few of my comments for it; it's up to you Nick. @nick.hiebert – Funk Forty Niner May 07 '14 at 20:19
  • I never know how to do that. I've looked in the past and haven't been successful. @Fred-ii-. – nickhiebertdev May 07 '14 at 20:28
  • I can't be of further help. – Funk Forty Niner May 07 '14 at 20:40

4 Answers4

0

You should add in head section of your html:

<base href='http://[your_domain_here]/' />

As [your_domain_here] you should insert either your domain or your domain with directory in case your installation is in directory (for example example.com/yoursite/ )

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
0

Unclear why you have it set like this:

<link rel="stylesheet" href="./css/styles.css"/>

I would recommend removing the . and using this instead:

<link rel="stylesheet" href="/css/styles.css"/>
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • 1
    Or possibly he meant `href='../css/styles.css'` ? – John Carroll May 07 '14 at 17:11
  • Who knows. The reality is the way I save my sanity with cases like this—since I program in PHP—is to just set a `base_path` variable & be sure to place it wherever things like this are needed. So to each his own! – Giacomo1968 May 07 '14 at 19:20
0

Maybe it work like this, try code above

<link rel="stylesheet" href="/css/styles.css" />
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Luís P. A.
  • 9,524
  • 2
  • 23
  • 36
0

It sounds like, you have Url Rewrites.

What you basicly say to the browser "Look at the Directory, where the current File is in, navigate to CSS Folder and Load styles.css as Style"

if your Adress is

example.com/index.php or
example.com/index.php?page=foo

Everything is ok. I Assume your Subpage is:

example.com/foo

Now the Browser is lookup following file (and get 404):

example.com/foo/css/style.css

So you should basicly link the Path like this:

<link rel="stylesheet" href="/css/styles.css" />

Note that there is no Point in the Beginning, which means, the Path beginns in the Root Directory:

example.com/css/style.css

If your Using Firefox you can Press CRTL+Shift+K and activate Network. Then you can see, errors because of 404 or 403 etc.

Regards

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
  • That's not `Url Rewrites.` – Damien Pirsy May 07 '14 at 17:22
  • What is not Url Rewrite? How do you call it then if you make foo.com/index.php?page=bar to foo.com/bar? :) – Christian Gollhardt May 07 '14 at 17:28
  • 1
    That has nothing to do with OP's problem (which, btw, has been solved several times minutes before). If you re-read the question, and see the screenshot, it's clearly just a path issue on pages different from the index – Damien Pirsy May 07 '14 at 17:31
  • Yeah I see the problem is resolved. Not seen this before. But OP didn't have said which was the reason of error. I assume, he has deleted the point, what also my advice was. But what is the source of the error? If he make it like /index.php?page=foo, he would never asked this question (Everything would work as expected). If he call /inc/nav.contact.php he wouldn't say include. So please tell me an other reason for this error, that i have not suggested. – Christian Gollhardt May 07 '14 at 17:39
  • Please re-read `I know it has something to do with locations`, plus the last 3 lines of the question + look at the screenshot. Of course OP didn't say the reason of his error, he would have solved it already otherwise. I don't know how and where you assumed the `page=foo` thing – Damien Pirsy May 07 '14 at 17:45
  • Okay, i misunderstood this. If I read the headline and look at the Screenshot, it sounds like the index.php?page=include style. Never thought the other Folders in the root are "Sub Pages" – Christian Gollhardt May 07 '14 at 17:58