Project:Taxonomy Image
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:critical
Assigned:Unassigned
Status:active

Issue Summary

<?php

foreach (taxonomy_node_get_terms($node->nid) as $term) {
    if (
$image = taxonomy_image_display($term->tid, "align='right'")) {
      print
"<a href='taxonomy/term/" . $term->tid . "'>" . $image . "</a>";
    }
}
?>

why cant i call the image with this in the teaser?

Comments

#1

Priority:normal» critical

hello i put it into my theme node.tpl.php so why wont it show ?? :D

#2

Hi,

I'm not quite sure if this is similar issue, but I am using recursive image display.
I've added this code to node.tpl.php (and I use the pixture theme)

foreach (taxonomy_node_get_terms($node->nid) as $term) {

echo "Debug : tid is ". $term->tid."<br>";
echo "Debug : term name is ". $term->name."<br>";
   
    if ($image = taxonomy_image_display($term->tid)) {
        
    $output .= "$image";
    }
  }
echo $output; 

The resultant is :

Debug : tid is 329
Debug : term name is ACHESON

... so both of these bars are known .... but $output always returns a null.

The term ACHESON does not have a taxonomy image added, but it's parent does.

Happy to answer any questions in hope of a solution.

Many thanks in advance.

D.

#3

can anyone help us ?

#4

Both of those look like they should work (although I am not a theme guru). However it is unnecessary; the taxonomy_image_link_alter add-on module will do that for you with no theme changes.

#5

that addon sounds like it replaces the link with an image

with this we would like to add addition image link at another location

i justr would like to see the variable and we theme it

#6

Here's a working template:

<?php
  echo '<div id="node-'. $node->nid .'" class="node'. ($sticky ? ' sticky' : NULL) . ($status ? NULL : ' node-unpublished') .'">';
  echo $picture;

  if ($page == 0) {
    echo '<h2><a href="'. $node_url .'" title="'. $title .'">'. $title .'</a></h2>';
  }

  if ($submitted) {
    echo '<span class="submitted">'. $submitted .'</span>';
  }

  echo '<div class="content clear-block" style="background:#ffe8e8;">'. $content .'</div>';

  echo '<div class="clear-block"><div class="meta">';
  if ($taxonomy) {
//    echo '<div class="terms">'. $terms .'</div>';
//    $output = NULL;
    $output = t('Tags:') .' ';
    foreach ($node->taxonomy as $term) {
      if ($image = taxonomy_image_display($term->tid)) { 
        $output .= "$image";
      }
    }
    echo $output; 
  }
  echo '</div>';

  if ($links) {
    echo '<div class="links">'. $links .'</div>';
  }
  echo '</div>';
  echo '</div>';

#7

Status:active» fixed

temp

Automatically closed -- issue fixed for two weeks with no activity.

#8

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

#9

Status:closed (fixed)» active

NancyDru

I copied your code, but it won't work for me, the image doesn't display.

In my node.tpl.php file I have:

<?php
$spaces
= db_fetch_array(db_query("SELECT stock FROM {uc_product_stock} WHERE nid = $node->nid"));
?>


<div class="node <?php print $node_classes ?>" id="node-<?php print $node->nid; ?>"><div class="node-inner">

  <?php if ($page == 0): ?>
    <h2 class="title">
      <a href="<?php print $node_url; ?>"><?php print $title; ?></a>
    </h2>
  <?php endif; ?>

  <?php if ($unpublished) : ?>
    <div class="unpublished"><?php print t('Unpublished'); ?></div>
  <?php endif; ?>

  <?php if ($picture) print $picture; ?>

  <?php if ($submitted): ?>
    <div class="submitted">
      <?php print $submitted; ?>
    </div>
  <?php endif; ?>

  <div class="content">
<table width="100%">
<tr>
<td width="70%" rowspan="4" valign="top"><?php print $node->content['body']['#value'] ?></td>
<td>
<?php
 
echo '<div class="clear-block"><div class="meta">';
  if (
$taxonomy) {
    foreach (
$node->taxonomy as $term) {
      if (
$image = taxonomy_image_display($term->tid)) {
       
$output = "$image";
      }
    }
    echo
$output;
  }
  echo
'</div>';
?>

</td>
</tr>
<tr>
<td>
<div class="field field-type-text field-field-location">
  <h4 class="field-label">Location:</h4>
  <div class="field-items">
      <div class="field-item"><?php print $node->field_location[0]['view'] ?></div>
  </div>
</div>
</td>
</tr>
<tr>
<td>
<div class="field field-type-text field-field-location">
  <h4 class="field-label">Start Date:</h4>
  <div class="field-items">
      <div class="field-item"><?php print $node->start_format ?></div>
  </div>
</div>
</td>
</tr>
<tr>
<td>
<div class="field field-type-text field-field-location">
  <h4 class="field-label">Spaces Available:</h4>
  <div class="field-items">
      <div class="field-item"><?php if ($spaces['stock'] > 0) { echo $spaces['stock']; } else { echo "<span style='color: red'>No spaces available</span>"; } ?></div>
  </div>
</div>
</td>
</tr>
</table>
<?php if ($spaces['stock'] > 0) { print $node->content['add_to_cart']['#value']; } ?>
  </div>

  <?php if ($links): ?>
    <div class="links">
      <?php print $links; ?>
    </div>
  <?php endif; ?>

</div></div> <!-- /node-inner, /node -->
?>

It won't display the image..... I know the image is loaded correctly; I can see it when I edit my taxonomy.

Thanks

Glenn

#10

In my case in node.tpl.php, the function taxonomy_node_get_terms returned an emtpy array. Yet all the tids were stored in$node->taxonomy.

So a working snippet in node.tpl.php would be:

<?php
 
foreach ($node->taxonomy as $term) {
    if (
$image = taxonomy_image_display($term->tid, 'title="'.check_plain($term->name).'"')) {
      print
l($image, 'taxonomy/term/'.$term->tid, array('html' => true, 'attributes' => array('alt' => check_plain($term->name))));
    }
  }
?>

Should be part of documentation!

#11

morningtime: The code you provided works BUT! How to display only images that belong to certain vocabularies?

#12

How about

<?php
 
// List of vocabulary ids (vid) to use
 
$wanted = array(3, 5);
  foreach (
$node->taxonomy as $term) {
    if (
in_array($term->tid, $wanted) ) {
      if (
$image = taxonomy_image_display($term->tid, 'title="'.check_plain($term->name).'"')) {
        print
l($image, 'taxonomy/term/'.$term->tid, array('html' => true, 'attributes' => array('alt' => check_plain($term->name))));
      }
    }
  }
?>

#13

nevets:

Thank you for quick reply!

But your code does't work for me :(

#14

Did you change $wanted = array(3, 5); and replace '3,5' with a comma separated list of the vocabularies you want?

#15

Yes, sure.

#16

Typo: in_array($term->tid, $wanted) should have been in_array($term->vid, $wanted)

#17

nevets:

Thank you, now it works!

So, here is final edition:

<?php
  // List of vocabulary ids (vid) to use
  $wanted = array(3, 5);
  foreach ($node->taxonomy as $term) {
    if ( in_array($term->vid, $wanted) ) {
      if ($image = taxonomy_image_display($term->tid, 'title="'.check_plain($term->name).'"')) {
        print l($image, 'taxonomy/term/'.$term->tid, array('html' => true, 'attributes' => array('alt' => check_plain($term->name))));
      }
    }
  }

The solution has to be included in documentation.

#18

Hi volocuga.
That function works well but it generates an invalid XHTML code (print title attribute twice!).

The definitve code should be this:

<?php
// List of vocabulary ids (vid) to use
$wanted = array(NUMBEROFYOURVOCABULARY);
foreach (
$node->taxonomy as $term) {
   if (
in_array($term->vid, $wanted) ) {
      if (
$image = taxonomy_image_display($term->tid)) {
         print
l($image, 'taxonomy/term/'. $term->tid, array('html' => TRUE, 'attributes' => array('class' => 'taxonomy-image-links')));
      }
   }
}
?>

It passes W3C validator. Bye!