2

I'm trying to change the color of the nav links depending on what page you are on. It is a fixed header. (Here is the link to my site).

For example, on the front page it is black and easy to read -

enter image description here

But when you go to the site's posts the backgrounds are black, making the nav links impossible to read -

enter image description here

Is it possible to change the nav links based on the post's id?

Social Monster
  • 91
  • 2
  • 15
  • Based on post id's might be a bit of a pain in terms of maintenance, you probably want something more flexible. Are all posts going to have a black background? – Nick R May 27 '14 at 11:27
  • @Nick R, yeah, annoyingly – Social Monster May 27 '14 at 11:28
  • 1
    If all other pages have a black background it would be easier to say If on the Homepage, use black font, otherwise use white font. Wordpress has 'is_home()' for php, and some themes have a body class you might be able to use. – Aravona May 27 '14 at 11:30
  • ^ Yeah, and even easier if you're using Wordpress, as it adds it's own classes to the body tag, like `` and ` – Nick R May 27 '14 at 11:32

3 Answers3

1

You can give the body tag class by the post unique slug.

<body class="<?php print $post->post_name; ?>">

like here it will be:

<body class="blackfoot-phoenix">

and then in the css:

.blackfoot-phoenix #cats li a {
    color: white;
}

You can also do it with the post id: postid-193 that in the body class.

.postid-193 #cats li a {
        color: white;
}

You can see the postid if you right click and do "View Page Source".

justtal
  • 800
  • 1
  • 7
  • 16
0
<style type='text/css'> 
  #black a { color:black }
  #white a { color:white }
</style>

...

<a id="<?php echo$color;?>" href="" ></a>
SimplyAzuma
  • 25,214
  • 3
  • 23
  • 39
robin
  • 159
  • 5
0

Depending on what you would like the outcome to be, you could give it a white background on the header links using css:

#cats li a {
  text-decoration: none !important;
  background-color: #fff;
}

By doing this it will appear normal, but on dark background it will have white behind the text. Alternatively you could assign it a class and set it per page using classes. Wordpress is not very friendly setting per page, but there may be some plugins available. Try something like this: https://wordpress.org/plugins/stylesheet-per-page/installation/

NickZA
  • 321
  • 1
  • 6