I would like to recommend the following update to PHPTemplate.engine to support ALT and TITLE tags for taxonomy images.

To support taxonomy_image the phptemplate_node function starts with the following lines:

  if (module_exist('taxonomy') && ($taxonomy = taxonomy_link('taxonomy terms', $node))) {
    if (module_exist('taxonomy_image')) {
      foreach (taxonomy_node_get_terms($node->nid) as $term) {
        $images[] = taxonomy_image_display($term->tid, "alt='Category: $term->name' title='Category: $term->name'");
      }
    }
  }
  else {
    $taxonomy = array();
  }

By adding the "alt='Category: $term->name' title='Category: $term->name'" parameter to the call to taxonomy_image_display, the taxonomy images have a nice information tab when the mouse hovers over the image.

Both the ALT and the TITLE should be used to support as many browsers as possible.

Paddy.

Comments

harald.walker’s picture

Could you explain, where in phptemplate you changed it and how your template file looks like? The module itself only comes with the marvin_2k.patch.

harald.walker’s picture

in other words:

If I change the code in the phptemplate_node function, I will get many taxonomy images on teaser pages. Only on node page this works as I would expect.

That's why I first tried it in phptemplate_page but I did't get very far.

harald.walker’s picture

I added following code to the phptemplate_page function. It is the same code that is being used by Taxonomy Context for the navigation menu.

 if (module_exist('taxonomy_image')) {
     $mode = arg(0);
     switch ($mode) {
      	case "taxonomy":
        	if (arg(2) == "vocab") {
          		$tid = 0;
        	} else if (arg(1) == "term") {
          		$tidcurrs = preg_split('/[+ ,]/', arg(2));
          		$tid = $tidcurrs[0];
        	}
        	break;
      case "node":
        	if (arg(2) == null) {
          		$tidscurr = taxonomy_node_get_terms(arg(1));
          		foreach ($tidscurr as $tidcurr) {
            		$tid = $tidcurr->tid;
            		break;
          		}
        	}
        }
  	$images[] = taxonomy_image_display($tid);
  }

and add

 'taxonomy_image'	  => ($images[0] != '' > 0 ? $images[0] : NULL),

to the array

$taxonomy_image can then be displayed in page.tpl.php. If $taxonomy_image is null a default image is being shown.

jeremy’s picture

It would be helpful to include actual patches, rather than snippets.

Also, these changes are not for the taxonomy image module, but for phptemplate. If you are hoping to get this merged, you'll need to select the correct project. If you do not hope to get them merged, you can leave them here so that other taxonomy_image module users can find them and apply them themselves.

fixweb@chattabene.fixweb.it’s picture

Title: Updates to PHPTemplate.engine to add ALT and TITLE tags to taxonomy images » Exteded code to get Multiple tax image with links
Version: » 4.6.x-1.x-dev
Assigned: Unassigned » fixweb@chattabene.fixweb.it

I'm added code to support Multi Tax Image
and have Link on tax image.

  if (module_exist('taxonomy') && ($taxonomy = taxonomy_link('taxonomy terms', $node))) {
	if (module_exist('taxonomy_image')) {
	  foreach (taxonomy_node_get_terms($node->nid) as $term) {
		$image = taxonomy_image_display($term->tid, "alt='Category: $term->name' title='Category: $term->name' align='right'");
	    $body .="<a href='?q=taxonomy/term/$term->tid'>".$image."</a>";
	  }
	}
  }
  else {
  $taxonomy = array();
  }

See on http://www.fixweb.it/

Thanks for your work.

fixus971’s picture

Version: 4.6.x-1.x-dev » master
Assigned: fixweb@chattabene.fixweb.it » fixus971

With new Drupal 4.7 I'm updated my tax img code
so now can separate Categories from Arguments

My node pushbutton theme now is:

<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
<?php print $picture ?>
<?php if ($page == 0): ?>
<?php
$taxcat = "";
$taxarg = "";
if (module_exist('taxonomy') && ($taxonomy = taxonomy_link('taxonomy terms', $node))) {
	if (module_exist('taxonomy_image')) {
		foreach (taxonomy_node_get_terms($node->nid) as $term) {
			if ($term->tid <= 4) {
				$taximg = taxonomy_image_display($term->tid, "alt='Categoria: $term->name' title='Categoria: $term->name' align='left'");
				$taxcat .= "<a href='?q=taxonomy/term/$term->tid' title='Categoria: $term->name'>".$taximg."</a> ";
			} else {
				$taximg = taxonomy_image_display($term->tid, "alt='Argomento: $term->name' title='Argomento: $term->name' align=''");
				if ($taximg == "") $taximg = "(".$term->name.")";
				$taxarg .= "<a href='?q=taxonomy/term/$term->tid' title='Atgomento: $term->name'>".$taximg."</a> ";
			}
		}
	}
}
?>
<span class="taxonomy"><?php print $taxcat ?></span>
<h1 class="title"><a href="<?php print $node_url ?>"><?php print $title ?></a>
<span class="taxonomy"><?php print $taxarg ?></span>
</h1>
<?php endif; ?>
<span class="submitted"><?php print $submitted ?></span>
<div class="content"><?php print $content ?></div>
<?php if ($links): ?>
<div class="links">&raquo; <?php print $links ?></div>
<?php endif; ?>
</div>
nancydru’s picture

Status: Active » Closed (won't fix)

Submit an actual patch against 5.x with a good use case, please.

nancydru’s picture

Assigned: fixus971 » nancydru
Status: Closed (won't fix) » Closed (fixed)

The ALT and TITLE attributes are provided by the base module without need for theme fiddling.