Closed (duplicate)
Project:
Taxonomy Image
Version:
5.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
15 Jun 2007 at 16:12 UTC
Updated:
15 Feb 2008 at 16:16 UTC
I have searched at length to find how to use taxo image in page.tpl.php as a page header as opposed to in node.tpl.php. The best thing I could find was http://drupal.org/node/44922#comment-223646
Except that the foreach in this code creates a huge amount of errors in the logs. I see a lot of other people asking how to do this as well. Could you possibly provide some documentation, or even a snippet of code for this? If I can get it working I am more than happy to write up documentation and a complete step-by-step process for others.
Thanks.
Comments
Comment #1
Bevan commentedYes, documentation on this would be useful. Here is an implementation I recently did;
The following code goes in template.php, and will probably need to be adapted to fit around existing code in the _phptemplate_variables() function. It could go in either the page of node case. It depends on taxonomy_image_get_url() which I introduced in this patch http://drupal.org/node/164448 which at time of writing I've only just submitted, so you'll have to apply it manually for this code to actually work -- at time of writing
You'll also need to put something like
<div id="header"<?php print $taxonomy_image_css ?>>
in your page.tpl file for this to become part of the theme.
I'll describe a more generalized implementation here that you could use to base documentation on:
Find template.php in your theme directory. If it doesn't exist, create it (there is documentation on this that you can link to).
In template.php, find function _phptemplate_variables(). If it doesn't exist in your template.php file, create it by copying and pasting this code (I think there's already documentation on this too):
Now you have to decide if you want your taxonomy image to be used in node.tpl.php, or in page.tpl.php. In this example I've used it in page.tpl.php, but you can use node.tpl.php instead. Once you've decided, look for the 'page' case in _phptemplate_variables() (or the 'node' case if you want to use node.tpl.php). If you copied the above code, you can change
case 'page':intocase 'node':.Inside this case we're going to set $vars['taxonomy_image'], which will become $taxonomy_image in page.tpl.php (or node.tpl.php). So start by putting
print $taxonomy_image;somewhere in page.tpl.php (there is documentation on this you can link to).Now in template.php in the case 'page', add this code
The following example is useful if you want to have multiple images. You'll have to use $taxonomy_images instead of $taxonomy_image in your tpl file.
I hope that's helpful. Let me know if/when it gets into documentation and/or the handbook so I can check it out! :)
By the way, to stop the errors in the code you linked to, wrap the foreach block in an if statement like this:
Comment #2
nancydruhttp://drupal.org/node/199061
Comment #3
muka commentedAnother cohice could be with the taxonomy_context module http://drupal.org/project/taxonomy_context
ex. in my page.tpl.php
I think this snippets could be a bit improved..
Thanks and compliments for the great job
Bye, luca
Comment #4
nancydruThanks, Luca. Interesting concept.