Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This feels like a fairly simple question, though I fear, may be a complicated answer. Is there an way (via plugin or code) to make a theme change some basic CSS elements based on a taxonomy term.

So if you have camera brands, and you site is all about cameras. Can you have pages about Kodak use a CSS file where colors are blue, and if Cannon it uses a CSS file that is red, etc. Basically you sub-theme your theme based on a taxonomy term?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Yes, you can. In many ways.

One way is to have custom templates based on tag or category slug. So, you just tag your posts appropriately and then WordPress will automatically select appropriate template.

If the template difference are miniscule, you can use php includes or wordpress includes to keep common content in other files.

Or you could do a custom include based on the value of the tag from the main theme file and provide CSS reference that way.

Or have inline CSS again controlled by php code inside the template.

share|improve this answer
    
My changes will be cosmetic. Where was blue now red. Image A now Image B. Very cosmetic. What I have are Pages with tags, and then some custom post types that need to have basically a CSS include in them depending on which color scheme they get. Alexandre, still the correct idea? –  cmurockstar Jan 7 '11 at 23:56
    
Why don't you just have a CSS file with name that incorporates the tag name? Then just get the tag name in the single.php template and use it to form the CSS file reference. It is probably easier to try it than to think it through. You can even do it with default 20/20 theme. –  Alexandre Rafalovitch Jan 8 '11 at 5:28
    
Alexandre, How do I tell PHP to add a style sheet? Don't those have to be specified in the Header of the page? –  cmurockstar Jan 17 '11 at 23:40
    
Yes, it needs to be in a header of the page. But single.php is a full page. Worst case, make it a copy of default.php (which has full functionality) and just add your extra include in the appropriate area. –  Alexandre Rafalovitch Jan 21 '11 at 0:38

There are several ways to approach this, mostly depending on how major changes in styling are going to be:

  • filter output of body_class() function (or wait for 3.1 in which according to docs terms are going to be included automatically) and including style differences in your main stylesheet;
  • echo additional styling inline (preferably when amount is minimal);
  • load additional stylesheets.

See Conditional Tags for how to check for different stuff and wp_enqueue_style() for loading additional stylesheets.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.