Automatic help block for nodes
I wanted an easy way to add a help block to some pages on my site, preferably so users could do it. Creating custom blocks and assigning to paths was cumbersome to say the least.
To do this create a new content type using CCK called 'helpfile' with a single additional text field 'path'. Then add a custom block with the code below. Users can then create help nodes pointing to the parent node. For example to add help to node/23 create a new node of type helpfile with the path set to "node/23". It will automagically appear when node/23 is visited. For multiple page webforms add the page number as a third part of the path for pages after the first, eg. setting path to "node/23/2" will create a help block for page 2 of the webform in node 23. I hope this is useful for someone.
<?php
//display a helpfile node (body only) in a block if the path matches
$path = $_GET['q'];
// for multi-page webforms
if ($_POST['details']['page_num']) {
$path .= '/'. $_POST['details']['page_num'];
}
// now look for a helpfile for this path
$result = db_query("SELECT nid FROM {content_type_helpfile} WHERE field_path_value = '%s' LIMIT 5", $path);
if (db_num_rows($result)) {
$output = '';
while ($row = db_fetch_array($result)) {
$node = node_load(array('nid' => $row['nid']));
$output .= '<h2 class="title">'. check_plain($node->title) .'</h2>';
$output .= '<div class="content">'. check_markup($node->body) .'</div>';
}
return $output;
}
else {
return;
}
?>