By hamsterbacke42 on
Hey Drupal-fans..
Ive got a problem. I want to something which I think a lot of Drupal-users are interested: Displaying a different header picture depending on taxonomy.
For my last site I did this with just creating several blocks with each a different background-css-image and then setting the block visibilty.
However, this time I want to try a more elegant way with the taxonomy image module.
After trying around I finally managed to let a taxonomy image appear within a node.
But here I got stuck: How do you display a taxonomy image for example on top of your page?
I stumbled on the following code, but it does not work I dont know why:
<?php if (module_exists('taxonomy_image')) {
$img = taxonomy_image_display(arg(2));
}
else {
$img = null;
} ?>
<h1 class="title"><?php print $img . $title ?></h1>
<div class="clear-block"></div>
Can anyone help me? pleeease
Comments
In general for this question
In general for this question there are three page types, taxonomy/{tid}, node/{nid} and all the rest. The snippet you have would only work for pages of the form taxonomy/{tid} and would be placed in page.tpl.php. And of course you need to have the images associated with the taxonomy terms. So when you say it does not work, what does happen? If you place a print statement in both the 'if' and 'else' do either show up?
details
Thank you very much for your replies.
Sorry for the rough problem description, I think I have to write more details:
I'm using the image taxonomy module. Then I already had associated a taxonomy image with the taxonomy image module to a taxonomy term, e.g. "climbing" (Content->Taxonomy->Images). And voila, on nodes with the term"climbing" the taxonomy image with the term "climbing" gets displayed inside the node (between the heading and the text).So far so nice.
However, as I said I wanted to display that taxonomy image in another place, e.g header of the page. So I placed the snippet in page.tpl.php at the place where I wanted, but nothing happens. I tried to place print statements in the "if" section and the "else" part of the snippet, then it prints the statement from the "if" part out correctly.
I dont 100% understand one thing you said:
So does it mean it cant get displayed on node pages except within the node? if I have a page with the node "climbing" in it and the taxonomy path "xx/climbing" it wont display in another place? Where can I use it then? on views pages ?
It seems that also on node pages like climbing/technique it will also only display taxonomy image within the node.
The taxonomy image module also comes with a block feature, but this is near to useless for my purpose as the maximum size for images is 96 pixel.
Thanks for your time to reply
Edit: Ok I think I came near to a solution. I use the taxonomy image feature block (node images) and edited taxonomy_image_blocks.module where the options of pixel sizes for images are (e.g. replace 96 with 750).
And thats all thats needed! great
Me Too
Hey
I am also trying to put the image in my header. But I can't figure out how to get all of the junk out of the content and just list the image. Any thoughts?
Thanks
-Tim
Have you checked out the Taxonomy image module.
Have you checked out the Taxonomy image module.
http://drupal.org/project/taxonomy_image
The taxonomy_image module allows site administrators to associate images with taxonomy terms. With the association created, an admin can then make a call to 'taxonomy_image_display()' from their theme or other PHP code to display the appropriate image.
The module allows the admin to create a one-to-one term-to-image relationship. With image display recursion, it is also possible to create a many-to-one relationship. This is useful if creating taxonomy hierarchies in which an entire tree of terms will use the same image. With recursion enabled, you only need to associate an image with the tree parent, and all children will automatically inherit the same image.
Features:
* Image configuration happens within existing admin/taxonomy menu structure.
markup when displaying images.
* Admins can add custom tags to
* Allows one-to-one term-to-image relationships.
* Allows many-to-one term-to-image relationships.
* Admin-permitted users can disable the images.
* Administrators can force images to be a standard size.
* May use the ImageCache module if it is available.
* Works with Views.
* Utilizes core file.inc and taxonomy.module APIs.
* Small module with specific, focused functionality.
Other Modules
Other modules that are known to utilize Taxonomy Image:
* Glossary
* FAQ
* Taxonomy List
-------------------
http://www.PrivacyDigest.com/ News from the Privacy Front (Drupal)
http://www.SunflowerChildren.org/ Helping children around the world ( Drupal)