Community Documentation

Navigate through categories inside a blog

Last updated May 12, 2011. Created by tsaorin on October 12, 2006.
Edited by ihsanfaisal, horncologne, bryan kennedy, taylesia. Log in to edit this page.

It's very useful knowing how to make the general taxonomy system fits with the needings of a multiblog site. If in our web there are many blogs independent, but the share the same vocabulary, there would be a problem when navigate using taxonomy links in a post.

I'll write here the code to make a term link go to a view with two arguments (the user id, and the term id).

In the full node view, the link in the terms will be like "blogterms/32/6"

  • blogterms will be a view.
  • 32 is the taxonomy term id
  • 6 is the user id (Remeber that the drupal blogs as listed using the author)

To obtain this link, in the node.tpl.php insert this php code for the terms linsting:

<?php
if ($terms) {
  if (
arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
   
$result = db_query('SELECT uid FROM {node} WHERE nid = %d ORDER BY uid DESC', arg(1)); // search node author in full view mode
   
$user = db_fetch_object($result);
   
$uid = $user->uid;
   
$nid = (int)arg(1);
  } else {
   
$result = db_query('SELECT uid FROM {node} WHERE nid = %d ORDER BY uid DESC', $node->nid); // search node author when you are in the blog home (/blog/6)
   
$user = db_fetch_object($result);
   
$uid = $user->uid;
   
$nid = $node->nid;
  }
}
$terms = taxonomy_node_get_terms($nid);
$output = "<ul>";
foreach (
$terms as $term) {
 
$output .= "<li><a href=\"/blogterms/" .$term->tid . "/" .$uid . "\">$term->name</a></li>";
}
$output .= "</ul>";
print
t('Tags:').$output;
?>

Then in the view "blogterms" you must use Arguments

Taxonomy: Term ID (The first argument)
User: UID is Author (The second argument)

nobody click here