Hi,

is it possible to associate somehow a picture with a taxonomy term? For example image would be shown next to each story on the main page.

Thanks.

Comments

boris mann’s picture

tip’s picture

I've installed both modules successfuly (taxonomy_context and node_image), going to the administration -> taxonomy I still can't add images to my terms, am I missing something ?

grohk’s picture

It is possible to do this. You must modify your chosen theme (I used xtemplate) as is directed in the INSTALL file with node_image. I used the node_image CVS version and then applied the patch from:

http://drupal.org/files/issues/imaged_nodes.patch

and suddenly everything worked. Still working out the kinks, but it seems to be working.

magnestyuk’s picture

In case you or someone else is still looking for the answer..

I was looking like mad for the place of image upload for terms... then I found it. You have to have taxonomy_context for this to work though, I think. Taxonomy_context puts the description of your taxonomy term in a message box directly under the taxonomy title on taxonomy pages like /taxonomy/page/or/10. In this message box, there's a link called "add images" which allows you to upload and associate an image with that taxonomy term.

cybe’s picture

I made a feature request for this feature here

tip’s picture

I think this feature is a must for drupal. I've got PHP/SQL skills(nextgencms.sf.net), but where to begin? ;)

cybe’s picture

So do I! (as I tried to explain in my feature request)

I know that the Polder theme does have this feature... but there isn't a version that works with Drupal 4.4.x. yet But the author Robert Polder say's he's working on it...

Perhaps you could dive into the polder theme and have a look at how he's done it?

frjo’s picture

This solution is a bit primitive but it works. All is done in the function name_of_theme_node.

// This is a primitive hack to get topic images. This array correlates $tid with image name.
$topic_images = array(
  "1" => "topic1.gif",
  "2" => "topic2.gif",
  "3" => "topic3.gif"
);

  if (module_exist("taxonomy")) {
    $terms = taxonomy_link("taxonomy terms", $node);
    $termimages = array();
    foreach (taxonomy_node_get_terms($node->nid) as $term) {
      if ($topic_images[$term->tid]) {
        $termimages[] = l("<img src=\"images/topics/". $topic_images[$term->tid] ."\" border=\"0\" alt=\"". $term->name ."\" align=\"right\" hspace=\"5\" vspace=\"5\" />", "taxonomy/page/or/$term->tid", array("title" => $term->description));
      }
    }
  }

  if (count($termimages)) {
    $termimage = $termimages[0];
  }

Then you just put $termimage where ever you want the image in the node. Remeber to remove the php open and close tags if you cut and past. See it in action at http://xdeb.org/.

cybe’s picture

nice =) I'll give it a go..

utmärkt..

php64’s picture

Dear frjo !

I have searched for your posted code in the Drupal folder but couldn't find the mentioned function to insert the code in ( function name_of_theme_node ) . Would you please tell the place in Drupal directory tree ?

Thanks a lot ,

frjo’s picture

I use my php theme "Slash" that borrows a lot of code from "Chameleon", the php theme in core.

If you use a xtemplate or a phptemplate theme it will be more work to implement this hack.

php64’s picture

Dear frjo !

I managed to insert the hack without problems into my slash theme .theme file. What remains now is how to use an image as a topic image. I made a folder in the root drupal directory and created topics folder inside it and put a PNG test image. How can I use it now ?

Thanks a lot for your help !

frjo’s picture

In the array $topic_images you must pair up a term id with a image file name.

Then you just put $termimage where ever you want the image in the node. See example below.

  $output .= "<div class=\"nodecontent\">";
  if ($main && $node->teaser) {
    $output .= $termimage . $node->teaser;
  }
  else {
    $output .= $termimage . $node->body;
  }
  $output .= "</div>";

As I mentioned in my original comment, it's a primitive hack.

hotch’s picture

Even if this thread is a bit old I hope someone maybe can help with this problem.

I've included the above code in my .theme file and the page generates just fine. My problem is that the image tag string gets converted to at text string in the output, so instead of the category picture I see the full Only local images are allowed. tag text with all its attributes as an anchor. I guess it must be something with l-function, but I can't figure out how to get around it. Has anyone had the same problem and managed to solve it? I run Drupal 4.6.3 my server.

frjo’s picture

You need to add some attributes to the l function. Here are the updated code.

  // This is a primitive hack to get topic images. This array correlates $tid with image name.
  $topic_images = array(
    '1' => 'topic1.gif',
    '2' => 'topic2.gif',
    '3' => 'topic3.gif'
  );

  $terms = array();
  if (module_exist('taxonomy') && $terms = (taxonomy_link('taxonomy terms', $node))) {
    $termimages = array();
    foreach (taxonomy_node_get_terms($node->nid) as $term) {
      if ($topic_images[$term->tid]) {
        $termimages[] = l("<img class=\"topic\" src=\"images/topics/". $topic_images[$term->tid] ."\" alt=\"". $term->name ."\" />", "taxonomy/term/$term->tid", array("title" => $term->description), NULL, NULL, FALSE, TRUE);
      }
    }
  }

  if (count($termimages)) {
    $termimage = $termimages[0];
  }
hotch’s picture

Great! Now it is working. Thank you very much!