I am trying to get the header of my Course Descriptions to print as such

CMMN A101 Communications Writing 3 hrs.

CMMN is the vocabulary term that has been assigned to this node type. It is currently printing only "A101 Communications Writing 3 hrs.".

Below is the code that I have in my template.php to style the H1, but it is not working.

function bulletin2009_format_title($node) {
	if($node->type == "course") {
		$term_list = taxonomy_node_get_terms($node->nid, $key='tid');
		$first_term = $term_list[0]->name;
		$node_title = "<h1>" . $first_term . " " . $node->field_course_number[0]['value'] . " " . $node->title . " " . $node->field_credit_hours[0]['value'] . "</h1>";
	}
	if($node->type == "graduate" || $node->type == "law" || $node->type == "undergraduate" || $node->type == "bulletin_main" || $node->type == "image") {
		$node_title = "<h1>" . $node->title . "</h1>";
	}
	return $node_title;
}

Here is the taxonomy term as it displays when I print_r($node).

    [taxonomy] => Array
        (
            [197] => stdClass Object
                (
                    [tid] => 197
                    [vid] => 19
                    [name] => CMMN
                    [description] => Mass Communication
                    [weight] => 8
                )

        )

I am currently using Drupal 6.10. If anyone can tell me where I am going wrong I would appreciate the assistance.

Comments

WorldFallz’s picture

Try this:

function bulletin2009_format_title($node) {
    if($node->type == "course") {
        $term_list = taxonomy_node_get_terms($node);
        $first_term = $term_list[key($term_list)]->name;
        $node_title = "<h1>" . $first_term . " " . $node->field_course_number[0]['value'] . " " . $node->title . " " . $node->field_credit_hours[0]['value'] . "</h1>";
    }
    if($node->type == "graduate" || $node->type == "law" || $node->type == "undergraduate" || $node->type == "bulletin_main" || $node->type == "image") {
        $node_title = "<h1>" . $node->title . "</h1>";
    }
    return $node_title;
}
jabolles’s picture

Thanks. Worked like a charm.

netentropy’s picture

Is there anything you would have to change to make something like this work in a block?

Here is a derivative of this code that I need to work in a block

$node= "1196";

    if($node->type == "blog") {
        $term_list = taxonomy_node_get_terms($node);
        $first_term = $term_list[key($term_list)]->name;
        $node_term = "<h1>" . $first_term. "</h1>";
    }
    
 print $node_term;

WorldFallz’s picture

$node is supposed to be a node object, not the node id: $node = node_load(1196);