When viewing a nome, the taxonomy terms are listed, as they normally are. These are linked to pages that list the nodes that have that taxonomy term.

How do I change the taxonomy link to point to the taxonomy node?

Thanks!

CommentFileSizeAuthor
#5 taxonomynode-1017842.patch1.13 KBziomizar

Comments

daigorocub’s picture

Title: In a node, list the taxonomy terms to the taxonomy node » In a node, list the taxonomy terms linked to the taxonomy node
daigorocub’s picture

Title: In a node, list the taxonomy terms linked to the taxonomy node » In a node, list the taxonomy terms linked to the corresponding taxonomy nodes
daigorocub’s picture

This is probably not the correct way of using drupal. Anyway I made a function on template.php. This collects the urls to the taxonomy nodes and makes some links with the taxonomy terms:

<?php
# template.php
function listaNodeSectores($geturl){
    //get alias of URL
    $path = drupal_get_path_alias($geturl['q']);
    //break path into an array
    $pathArray = explode('/', $path);
    $arraysize = sizeof($pathArray);

    if ($arraysize>0) {
      $nodeId = $pathArray[$arraysize - 1];
    }
//  echo "nodeID: ".$nodeId;

    $node = node_load($nodeId);
    $termos = taxonomy_node_get_terms($node);

    foreach($termos as $term){
        $termNodeID = _taxonomynode_get_nid_from_tid($term->tid) ;
        $termNode = node_load($termNodeID);

        $tmp = $pathArray;
        $tmp[$arraysize - 1] = $termNodeID;
        $tmp2 = implode('/', $tmp);
        // devolve os urls completos:
        $termNodeUrls[] = '<a href="'.url($tmp2).'">'.$termNode->title.'</a>';

    }

    return  $termNodeUrls;
}
?>

Then, I use it in "node-produtos.tpl.php" like so:

<?php
$lista_sectores = listaNodeSectores($_GET);
$str = '<ul id="guy-menu-banner" class="menu">';
foreach($lista_sectores as $sector){
	$str .= '<li>'.$sector.'</li>';
}
$str .= '</ul>';
echo $str;
?>
daigorocub’s picture

Status: Active » Needs review

Please review this because I think it needs polishing.

ziomizar’s picture

StatusFileSize
new1.13 KB

Hi @daigorocub,

I have the same issue, and i have solved using hook_link_alter.
This patch change automatically url of taxonomy into the taxonomynode.

Let me know if it work.

edchan’s picture

Hi @ziomizar,

Thanks for the patch. I've used your patch but somehow I think it has an issue with path and pathauto modules. I've modified it but not sure if this is the right thing to do (I'm new in the community):

function taxonomynode_link_alter(&$links, $node, $comment = NULL) {
  foreach ($links as $module => $link) {
	$term = strstr($module,'taxonomy_term_'); //select the term only
    if ($term){
      $tid = substr($term,strlen('taxonomy_term_')); //get the tid
      $nid = _taxonomynode_get_nid_from_tid($tid); //check if the term is a taxonomynode
	  $taxonomy_node = node_load($nid);
	  // Link back to the taxonomynode and not the taxonomy term page
	  $links[$module]['href'] = url('node/' . $taxonomy_node->nid, array('absolute' => TRUE));
	  $links[$module]['title'] = $taxonomy_node->title;
	}
  }
}