Displaying Taxonomy on Your Product Page.

mach5_kel's picture
Offline
Joined: 03/25/2008
Juice: 79
Displaying Taxonomy on Your Product Page.

Im glad you found it usefull. So many people on drupal and here at ubercart have been great at answering questions. I felt like I needed to start posting some help for other people where I could.

So... #2.

-- TAXONOMY DISPLAY ON YOUR PRODUCT PAGE --

The back story

My site is not currently up, so I cannot point to an example. However, I wanted more than one taxonomy vocab for each product. So far, no problem. Just heard over to the taxonomy module, make some new vocabs, add some terms, associate with the node type product. Great.

For example. I am selling online courses.

I want a vocab of Authors (Tom, Dick, Harry), Type of Course (Online, Distance Education, Live) and Catalog (Courses about Internal Medicine, Surgery and Orthopedics).

The Problem

All the terms are mashed together on my product page. I want it to look like this:

Author: Tom
Type of Course: Online
Catalog: Surgery.

Not like this:

Tom, Online, Surgery.

Plus, I wanted authors at the top of the page, and catalog at the bottom.

This way, when people are surfing my products, if they find a course by Tom, they can just click his name, and it shows all the courses tagged as Tom. This is a great way to group products by Brand, Colors, Sizes, Mens and Women, etc etc. You get the idea.

The Solution

Listing each Vocab by its VID. (Vocabulary ID Number).

STEP 1.

Head over to YOURSITE/admin/content/taxonomy and click the link edit vocabulary . Now check your http: location. Should be something like admin/content/taxonomy/edit/vocabulary/5

Take that very last number. That is your VID.

STEP 2.

Post the following code into your node-product.tpl.php

  <?php
$terms
= taxonomy_node_get_terms_by_vocabulary($node->nid, 7);
foreach (
$terms as $term) {
 
$tagsOne[] = l($term->name, taxonomy_term_path($term));
    }
print
t("Author") . ": " . implode(' | ', $tagsOne);
?>

STEP 3.

Where it says ($node->nid, 7); add your own VID instead of the 7.

STEP 4.

Change the word "Author" to be whatever you want your Vocab to be name on your product pages. It will look like "Author: YOUR TERMS HERE". Try it out and see. You can write anything really.

Step 5.

If you want more than one Vocab, copy and paste the code again and you must change the words "TagsOne" to be "TagsTwo", "TagsThree", and so on. (OK, you dont need to number them that exact way, but I do suggest you do. Keep track of things folks).

Notice "TagsOne" is written twice. Don't forget to change both instances or it won't work.

For example:

<?php
$terms
= taxonomy_node_get_terms_by_vocabulary($node->nid, 5);
foreach (
$terms as $term) {
 
$tagsTwo[] = l($term->name, taxonomy_term_path($term));
    }
print
t("Approved") . ": " . implode(' | ', $tagsTwo);
?>

<br />

  <?php
$terms
= taxonomy_node_get_terms_by_vocabulary($node->nid, 6);
foreach (
$terms as $term) {
 
$tagsThree[] = l($term->name, taxonomy_term_path($term));
    }
print
t("Pending") . ": " . implode(' | ', $tagsThree);
?>
 

Final Notes

In my experience, this will not work with any special CCK - Taxonomy modules. Why.. no clue. Just doesnt output properly. PS, those modules destroyed my catalog page and terms. Use them with caution for sure. I couldnt fix it afterwards either. Live and Learn

Thats it...