Navigate through categories inside a blog

Last modified: March 7, 2009 - 17:24

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 web 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-blog.tpl 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" youy must use Arguments

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

 
 

Drupal is a registered trademark of Dries Buytaert.