Similar By Term
Another straight forward method for creating a silo structured website in Drupal using any node type is by using the Similar By Term module combined with a custom node template. This will somewhat replicate the Book module's linking structure. It does not contain the hierarchy structure that comes with the Book module. However, it's a quick and dirty method that will get the job done.
Similar By Term
This module will list inside a block the titles of nodes that are all tagged with the same term.
Once you activate the module:
- go to Administer > Site Building > Blocks.
- Click on the configure link next to the block titled "Similar entries from ANY vocabulary".
- Here you can change the default title of the block and specify how many nodes you want to display. By default, it is set to five.
- Once you save the configuration, activate the block by selecting the block region in the drop down menu. This block will behave similar to the Book Navigation block.
Custom Template
To add the same type of previous/next linking structure that you see at the end of a book page, you will need to create a custom node template. This requires editing the code in your files.
- First, open the template.php file located in themes/yourtheme.
- Add the following snippet of code to the end of this file and save.
//next previous links with titles
function next_prev($current_nid, $type, $button_type, $label, $class) {
$tid = db_result(db_query(db_rewrite_sql("SELECT tid FROM {term_node} WHERE nid = $current_nid;")));
if (empty($tid)){ //validate that the image 'does' have a tid
return '';
}
switch ($button_type) {
case 'prev':
$sort= 'DESC';
$case = '< ';
break;
case 'next':
$sort = 'ASC';
$case = '> ';
break;
case 'parent':
$name = db_result(db_query(db_rewrite_sql("SELECT name FROM {term_data} WHERE tid = $tid;")));
return l($label.$name, "$type/tid/$tid", array('title' => $name, 'class' => $class));
break;
default:
return NULL;
break;
}
$sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid ";
$sql .= "INNER JOIN {term_data} r ON t.tid = r.tid WHERE n.type = '". $type ."' AND n.nid ". $case;
$sql .= $current_nid ." AND r.tid = ". $tid ." AND n.status = 1 ORDER BY nid ". $sort;
$result = db_fetch_array(db_query(db_rewrite_sql($sql)));
$newtitle = $result['title'];
if (!$result) {
return NULL;
return l($label.$name, "$type/tid/$tid", array('title' => $name, 'class' => $class));
} else {
return l($label.$newtitle, 'node/'. $result['nid'], array('title' => $result['title'], 'class' => $class));
}
}
- Inside your themes/yourtheme directory, find the file titled 'node.tpl.php'.
- Copy this file and name it 'node-yournodetype.tpl.php', replacing yournodetype with whatever type you are using. For example, if you want to use the story node type, your file would be node-story.tpl.php.
-
Place the following code snippet where you want the links to appear, usually before the last
</div>tags. - Replace 'story' with your chosen content type.
<?php
if ($terms && arg(0) == 'node' && is_null(arg(2))) {
$next = next_prev($node->nid, 'story', 'next', '', 'link');
$previous = next_prev($node->nid, 'story', 'prev', '', 'link');
print '<p><center>';
if ($previous){ print '< ' . $previous;}
print ' | ';
if ($next){ print $next . ' >';}
print '</center></p>';
}
?>This will display the linked titles of both the previous and next nodes that are tagged with the same taxonomy term. They are sorted by node id rather than weight.


