RelatedContent module: Block with links to related content

RelatedContent allows privileged users to easily select for a node other nodes to be displayed along with it. Nodes that can be selected are provided by one or more views of the Views module. How the nodes are displayed is configurable, as well as themeable. The module also provide a small but powerful API for advance users.

This code snippet make use of the API to accomplish a block with links to related content, as seen in this image:

<?php
if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
 
$host_node = node_load($nid);
 
$grouped = relatedcontent_variable_output_grouped($host_node->type);
  if(
$groups = relatedcontent($host_node, $grouped)) {
    foreach(
$groups as $group => $nodes) {
      if (
$nodes) {
       
$links = array();
        foreach(
$nodes as $node) {
         
$links[] = l($node->title, "node/$node->nid");
        }
       
$title = relatedcontent_group_title($group, $grouped, $host_node->type);
        print
theme('item_list', $links, $title);
      }
    }
  }
}
?>

To use the code snippet, just cut'n'paste it into a block with PHP Input filter.

 
 

Drupal is a registered trademark of Dries Buytaert.