description
These snippets allow you to insert Taxonomy images into your nodes, when using the taxonomy_image.module.
Before doing a lot of extra work for yourself, there are several Taxonomy Image add-ons distributed with the package and that virtually eliminate all this extra work.
usage
- Requires the taxonomy_image.module to be installed and enabled
- Use a text editor like notepad.exe or equivalent to copy and paste the snippets below into your template.php file and node.tpl.php (or node-type.tpl.php) files respectively
- Upload your edited your template.php file and node.tpl.php (or node-type.tpl.php) files to your active theme folder.
step 1 of 2
To override the default taxonomy_image layout copy the following snippet, using an editor like notepad.exe, name it TEMPLATE.PHP and upload it to your active theme folder.
If you already have a TEMPLATE.PHP file in your active theme folder, simply add the above to the existing TEMPLATE.PHP file and upload it.
NOTE: This is not to be confused with the template.php file in the /THEMES/ENGINES/PHPTEMPLATE folder. themes/engines/phpTemplate
.
<?php
function _phptemplate_variables($hook, $vars) {
if ($hook == 'node') {
if (module_exist("taxonomy_image")) {
foreach (taxonomy_node_get_terms($vars['node']->nid) as $term) {
$vars['taxonomy_images'][] = taxonomy_image_display($term->tid, "alt='$term->name'");
}
}
}
return $vars;
}
?>
step 2 of 2
Copy the following snippet into your your node.tpl.php or node-type.tpl.php file, where you want the taxonomy images to display. Edit the class names and adjust the layout to suit.
<div class="taximage">
<?php print $taxonomy_images[0] ?>
</div>
Comments
Summary Guide to taxonomy_image
This is the starting point for helping me set up taxonomy_image. Having read tons of posts/comments, I put together a Summary Guide to taxonomy_image
-------------------------------------------------
AdAstra.ca - Optimze the Web. Optimze the World.
Drupal5 taxonomy image
The code didn't work for me in Drupal 5 until I changed
module_exist
tomodule_exists
:Does anyone know how to insert taxonomy images into the page template (page.tpl.php) and not just the node templates?
taxonomy image in the page template
I dunno how great of a solution this is but you can try this (in drupal 5).
and then in the page.tpl.php file use
print $GLOBALS['taximages'][1]
or something similar likeit should probably involve some if exists type logic...
You can also change
You can also change this:
if ($hook == 'node') {
to:
if ($hook == 'page') {
to display the images in pageview.
Simpler than the rest
How about cutting out step 1 and just adding this to node.tpl.php :
Works for me, displays all the images for any of the taxonomies that have images assigned to them.
for Drupal 6 you use
in node.tpl.php
Probably don't need this
With the contributed add-ons to Taxonomy Image, virtually all theme modifications are unnecessary.
NancyDru (formerly Nancy W. until I got married to Drupal)
NancyDru
Drupal 7 - How to display taxonomy images in nodes
Hi,
Can anyone point me in the direction of a good resource for displaying taxonomy images in nodes for Drupal 7?
I have only 1 vocabulary and every piece of content is allocated to one of 12 terms in that vocabulary.
Ideally what I'd like to achieve is to allow users to upload their own image or if they don't substitute the for the relevant taxonomy term.
Thanks heaps!
Looking for the same thing
Looking for the same thing