Navigate through categories inside a blog

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.

There a interesting post titled "Blogs categories" very useful: http://drupal.org/node/20260 .

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)

And voilá

Possible link problem

pdchapin - April 14, 2008 - 20:28

I'm getting an "access denied" message on your link near the top.

 
 

Drupal is a registered trademark of Dries Buytaert.