I know that this might sound really boring for all those in the know but having struggled with this module in its previous and current incarnations I'm just about to give up.

So could someone please give a simple example of code that one can put in to a page.tpl template file so that the images show at the to of a listing for a taxonomy term.

Much appreciated.

--
Ade Atobatele

Comments

nancydru’s picture

Priority: Critical » Normal

I appreciate the urgency you may feel, but this is simply not a critical issue.

If no one else comes up with something, I'll play around with this and see what i can do.

Nigeria’s picture

Thanks...

Waiting with bated breath...

nancydru’s picture

For information on changing your themes, I suggest the handbook section: PHPTemplate theme engine

  1. Create a copy of your page.tpl.php and name it page-taxonomy-term.php.
  2. Locate where the title is being formatted (usually with an <h1> tag).
  3. For example, Bluemarine has: <h1 class="title"><?php print $title ?></h1>

  4. Replace this line with this code:
  5.         <?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>
    
  6. Save the code.

You should be in business now.

nancydru’s picture

Assigned: Unassigned » nancydru
Status: Active » Fixed
Nigeria’s picture

Thanks a million...it works...well almost!

It works on a URL like http://www.example.com/taxonomy/term/948 but not its equivalent http://www.example.com/category/1/948

So what do I have to add to get it to work with categories as well as taxonomies :)

---
Ade Atobatele

nancydru’s picture

Submit a well-tested patch. http://drupal.org/node/145836

Nigeria’s picture

Based on your code and others, I managed to cobble together the code below which works in page.tpl.php for both taxonomy term pages and individual nodes.

	if (module_exists('taxonomy_image')) {
		if ($image = taxonomy_image_display(arg(2))) {
			print $title . "<a href='../jump_to/" . $title . "'>" . $image . "</a>"; 
		}
		
		foreach (taxonomy_node_get_terms($node->nid) as $term) {
			if ($image = taxonomy_image_display($term->tid)) {
				print $term->name . "<a href='../jump_to/" . $term->name . "'>" . $image . "</a>";
    			}
		}
	}

In this instance terms have only one taxonomy image per term, while nodes can have multiple taxonomy terms associated with them.

I also use Path Redirect to redirect the image links to wherever I want them to go based upon the taxonomy term that they represent.

In this case I've created it to create a non-existent URL ../jump_to/xxxx (where xxxx is the name of the relevant term) which ensures that Path Redirect picks it up and does the appropriate redirection.

This hasn't been exhaustively tested, so I can't guarantee that it'll work in all cases.

--
Ade Atobatele

nancydru’s picture

Thanks for the feedback. Would you like to add this to the "Real Life" examples in the handbook documentation?

The Taxonomy Image Link Alter add-on will automatically take care of the taxonomy links. However, it will not set the path as you are doing. For that case, the Taxonomy Redirect module could be used. Or I think the TILA module could be modified to allow a base path option.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Nigeria’s picture

I almost thouight that I could follow your suggestion and put it as a handbook entry, but I've been testing the code that I uploaded and have found a bug.

If you put the code in a block the title and term names disappear while the image itself gets shown. Any idea why?

-- Ade Atobatele

nancydru’s picture

Which code is that? Template and block code won't be the same.

Nigeria’s picture

Ahhh................

What should the block code look like to be able to have the same functionality in a block?

I wanted to put it in a block, so that when in edit mode or admin mode the image, and its associated link, doesn't show.

Firstly this is following the principle that you should not give a user an option that you don't want them to actually exercise. When in either of those modes I just want the user to finish the immediate task rather that be able to jump out of the page leaving the task undone!

Secondly I need all the real estate possible when in admin mode on my fixed width template. Being able to put the code into a block allows me to use the block's configuration settings to hide the block when necessary.

--
Ade Atobatele

nancydru’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

I still don't know what code you're talking about or what your goal is. If you're talking about a block that shows the image associated with the terms for a node, there is a contributed module for TI that already does that.

nancydru’s picture

Title: Simple Example For A Taxonomy Term Needed Urgently » Simple Example For A Taxonomy Term Needed

obviously not too urgent

Nigeria’s picture

Urgent..but had a mighty cold, so went straight to bed!!!

Didn't realize that you had a new version out...looked at it and it does most of what I want...I might hack it though and get back to you.

-- Ade Atobatele

nancydru’s picture

There have been several versions since 5.x-1.1-beta1. The absolutely newest stuff, including caching, is in the 5.x-1.x-dev version.

nancydru’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No comment, closing.

Nigeria’s picture

I just noticed that

if ($image = taxonomy_image_display(arg(2))) {
print $title . "" . $image . "";
}

acts in a recursive manner whether or not the recursive flag is set. It even overrides individual settings in terms in term view. It works properly in node view (i.e. it does nothing)

I'm on the 5.x-1.x-dev version.

nancydru’s picture

When you say you're using a -dev version, it's a good idea to also tell what the date is on it. 5.x-1.3 should be out any moment and I strongly encourage trying it.

Nigeria’s picture

Version: 5.x-1.1-beta1 » 5.x-1.3

I'm now using the 5.x.1.3 version and the feature/bug still persists