Related Contents Block for Drupal
Usually, a Drupal site will come with Navigation block. However, it is not enough for complex categories just like this site. So, I modified book-like navigation block to show only related contents.
// configuration $myvocab = 3; $mylimit = 10; $includecurrent = false; // code $mycategory = array(); switch (arg(0)) { case 'node': $current = arg(1); $cats = taxonomy_node_get_terms_by_vocabulary($current, $myvocab); foreach ($cats as $cat) { $mycategory[] = $cat->tid; } break; case 'taxonomy': $current = 0; $mycategory[] = arg(2); break; default: $current = 0; $mycategory[] = 0; break; } $terms = taxonomy_get_tree($myvocab); $operator = "or"; $result = taxonomy_select_nodes($mycategory, $operator); $count = 0; $items = array(); while ($obj = db_fetch_object($result)) { $node = node_load(array('nid' => $obj->nid)); if ($node->nid != $current || $includecurrent) { $items[] = l($node->title, "node/". $node->nid); $count++; if ($count >= $mylimit) { break; } } } if (empty($items)) { return ''; } return theme('item_list', $items);
- sugree's blog
- 1697 reads
Recent comments
2 years 11 weeks ago
2 years 15 weeks ago
2 years 16 weeks ago
2 years 16 weeks ago
2 years 17 weeks ago
2 years 19 weeks ago
2 years 19 weeks ago
2 years 19 weeks ago
2 years 19 weeks ago
2 years 20 weeks ago