How would I customize my code in my page.tpl.php in order to have it display a particular template if a page (node) has a particular taxonomy attached to it. IE: if node/43 had the taxonomy "music" how could I make it display a different template?

This is one Idea I batted around, and while it doesn't seem to break the design, it also doesn't work either:

if  ($taxonomy->term == '24') {
    include 'page-music.tpl.php';
    return; }

Further, this option only works for displaying the taxonomy listing, not the nodes attached to that taxonomy itself:

if  (arg(0)=="taxonomy" && arg(1)=="term" && arg(2)=="24") {
    include 'page-music.tpl.php';
    return; }

Any ideas? I really need this and don't want 5,000 lines of code in my site's template switcher! hehe!

Comments

styro’s picture

http://www.nicklewis.org/node/825

As an example of picking up a taxonomy term more than the styling method though. ie he is using differing CSS based on taxonomy rather than a different template.

But you might decide that you prefer the CSS method after all :)

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Example Knowledge Base built using Drupal

marcoBauli’s picture

There is a module that should do pretty well about what you ask:

http://drupal.org/project/taxonomy_theme

good luck ;)

Shivian Balaris’s picture

I already tried installing it through their instructions on their readme.txt and came up with an error... I know this should be a simple line of code, can't someone help?

nevets’s picture

Consider that each page might be a single node, a list of nodes or something else completely. In your case you only case about the single node case so you test would start with something like this.

if ( $node )

This checks to see if $node is set in the current "call" to page.tpl.php and we only want to do something if it is set. The next part depends a lot on how your sight is setup and how you have categorized things. In general terms a node can be associated with any number of taxonomy terms so you can not simply check for a single term using a comparision operator.
You can use either calls to taxonomy functions or SQL to determine the set of terms a given node has.