Drupal 6 + Views 2 : Created similar node based on Node Title

Category:

I need my node to show related nodes below it. Since I know that my Node Title will be very similar in the name but different Season or Number like example below.

Node 1 - Final Destination DVD
Node 2 - Final Destination DVD 2
Node 3 - Final Destination DVD 3
Node 4 - Lost Season 1
Node 5 - Lost Season 2

When I open Node 1, links to Node 2 and Node 3 should be there below the content.

When I open Node 5, links to Node 4 should be there below the content.

I can do that by set Views as below:

1. Create Views name "Related Title"

2. Add an argument type "Node: Nid"

3. Choose "Provide default argument" under "Action to take if argument is not present:"

4. Select "PHP Code" under "Default argument type:"

5. Use the code Below :

<?php // Reset Counter
$i = 0;
// Truncate node title to 8 Characters
$truncatetitle = truncate_utf8(drupal_get_title(), 8, FALSE, FALSE);
// Run SQL to search for similar node title
$sql = "SELECT n.nid FROM {node} n WHERE n.title LIKE '%" . $truncatetitle . "%'";
$result = db_query($sql);

while ($node = db_fetch_object($result)) {
if ($i ?> 0){ $nids .= ',';}
$nids .= $node->nid;
$i++;
}
return $nids;
?>

6. Also check on "Allow multiple terms per argument."

7. Save it.

8. Set up the "Fields" that you want to display.

9. Add "Block" Display.

10. Under "Block" -> "Admin". Set "Block: Block admin description" to "Related Title"

11. Put that Block in to where you want it to display.

http://drupal.org/node/302498#comment-1126227

Comments