By patoshi on
Hi,
How do I access taxonomy terms array in page.tpl.php? The $node variable and $terms variable is only accesible in node.tpl.php. I need to get access to this variable so i can add a class to the body tag.
thanks
Hi,
How do I access taxonomy terms array in page.tpl.php? The $node variable and $terms variable is only accesible in node.tpl.php. I need to get access to this variable so i can add a class to the body tag.
thanks
Comments
Hi, Here is your
Hi,
Here is your answer:
<pre><?php print_r($node); ?></pre>You can use that to view the entire $node array on the page.tpl.php. Put right under the body tag to have it displayed then select what var you want to use after that.
take care.
$node is available in page.tpl.php if viewing a single node
$node is available in page.tpl.php if viewing a single node in which case $node->taxonomy is an array of taxonomy terms.
one solution...
There may be a better solution but I had a similar problem (I wanted an ID on each body) and I solved it. My suggestion is:
In your template.php (assuming you're using Drupal 6) write out the following loop:
Then, in your page.tlp.php you can reference the variable as $body_class. I know this will work with a single taxonomy term but you will need to declare $body_class as an array if you want to use mutiple taxonomy terms. That I haven't tested.
Hi, Anyone have altered this
Hi,
Anyone have altered this code please to use multiple taxonomy terms?
Could I also than chooses a taxonomy term per vocabulary?
greetings,
Martijn
solution with zen theming
I'm using zen for theming and wanted to add the taxonomy terms to the body classes, I used above function, but altered it thus:
This would also add all the terms as classes.
I'm unsure where your $variables comes from, isn't $vars the right one? At least in the Zen theme it is and Garland is using it as well. (where in the api is documentation on this?)
warning: Invalid argument supplied for foreach()
Thanks for the code snippets. The original is working for me but the version for multiple terms isn't. And both snippets generate the following message: warning: Invalid argument supplied for foreach() in /home/.../template.php on line 225.
Any ideas what could be going wrong with the argument?
When I use the version for multiple terms I'm not getting taxonomy terms back but page variables like "not_front"
Any assistance would be greatly appreciated
I also get the invalid foreach??
But it still works as such??
Anybody??
KD
The code assumes the node has
The code assumes the node has taxonomy terms, you can re-write as
to avoid the errors.
How to do this in Drupal 7?
How to do this in Drupal 7?
Drupal 6.22 and Zen 6.x-2.1
Drupal 6.22 and Zen 6.x-2.1 subtheme
The above code does not work on my system, this does. Note that this code uses the termID, then term-name could easy contain spaces or get changed by the admin/user.
@steinmb
theme_preprocess_page()
theme_preprocess_page() should be YOURTHEMENAME_preprocess_page()