Show related or similar content in a block with Views 2 in Drupal. Here is a step by step tutorial on how to accomplish this.

I first found this method over at Drupal Easy: Using Views 2 and Drupal 6 to Create a Related Pages Block. I'm going to show you a similar method with a few minor adjustments.

As of this writing this is accomplished with Views 2 and Drupal 6.

  • Make a new view and call it whatever you want.
  • Add a Block Display
  • Add a new argument - Taxonomy: Term ID
    • Set up the argument with these options:
    • Provide Default Argument
    • Php Code:
    • $node=node_load(arg(1));
      if($node){
      foreach($node->taxonomy as $term){$terms[]=$term->tid;}
      return implode('+',$terms);
      }else {return;}
    • Check Allow Multiple Terms per Argument
    • Check Reduce Duplicates
  • Click Save

You need to Define at least one Field. I recommend adding Node Title.
I would also recommend adding some sort of sorting. You can have it by Post Date or if you have Statistics enabled in your Core (optional) modules, you can sort by what content is the most popular.

Now here is the added bonus. It doesn't make much sense to display the same piece of content that you are currently looking at. So here is how you remedy that.

  • Add another Argument - Node: Nid
  • Then set the argument with these options:
    • Provide Default Argument
    • Node ID from Url
    • Check the Exclude from Argument
  • Click Save

This takes out the current piece of content that you are currently viewing. Simply drop this block in a sidebar and Views will take care of the rest.

Make sure and Subscribe to this blog to follow along with other Tips, Tricks, and Tutorials.