1

I need to change a link on the headers of a site depending on what category the page is. currently we are using php's switch/case/break to switch out the entire "a href ...etc" link depending on the category, so for example:

case 'red': ?>
<a href="red.html">red</a>
<?php break;
case 'blue': ?>
<a href="blue.html"></a>

and so on.

is there a way to do this with css and the body id? example: body id="red", and something besides php or javascript could change the link, like css' content:before or :after? i can't figure out how to apply that to inside the a tag. thanks.

elixenide
  • 44,308
  • 16
  • 74
  • 100
midknyte
  • 587
  • 3
  • 6
  • 18
  • Can you pls show us some code, Im not sure what u r asking? Do yu want to Change the Style or the `href`-Attribute – j_s_stack Jan 26 '15 at 05:05
  • http://stackoverflow.com/questions/165082/insert-a-link-using-css – j_s_stack Jan 26 '15 at 05:12
  • sorry, edited. so what i'd like to do, if possible, would be to change the word before .html in the href of a link depending on the body id without using php or javascript. – midknyte Jan 26 '15 at 05:14
  • 2
    http://css-tricks.com/css-content/ Look under Using Attributes, but why dont you want to use PHP? If you do it with CSS you mix Content and Design wich isnt a good thing – j_s_stack Jan 26 '15 at 05:15

1 Answers1

1

Why don't you do this:

$category = "red"
<a href="<?=$category;?>.html"></a>

If you want a CSS solution I would import a 'theme' file like:

category_red.css category_blue.css

On the head of the page I would call the desired category:

<link rel="stylesheet" type="text/css" href="category_red.css">
Paulo Lima
  • 76
  • 9
  • hmm, that $category = "red" sounds like a great alternative, thank you! if i were to use a css theme, what would i put in the theme that could change the link though? – midknyte Jan 28 '15 at 13:13
  • I would custom the tags and create classes that would be used on my web site like: Theme "Red" the CSS would be a{color:red;} and so on. a class example would be .link_color{color:red;} and then link – Paulo Lima Jan 28 '15 at 13:14