2

How can I display the title of related news in a block shown in node page?

For example, I create the content type "news", and add "news" nodes that have taxonomy terms taken from the same vocabulary; now I want to show the list of the related node basing on the taxonomy terms associated with the nodes.

How can I display this bock only for "news" nodes?

  • Can you retag this with either drupal-6 or drupal-7? Thanks. – tim.plunkett Mar 17 '11 at 19:25
  • @tim.plunkett: The user doesn't have an account on drupal.SE. – kiamlaluno Mar 18 '11 at 9:55
3

If I understand your question correctly, you can just use Views to accomplish this.

To display a block that lists other node titles with related taxonomy terms:

  1. Create a Block View
  2. Add the field Node:Title (make it link to its node)
  3. Add the argument Taxonomy: Term ID
  4. Configure this argument as follows:

    • Check Provide default argument
    • Select PHP Code
    • Add the following code:

    $node = node_load(arg(1));
    if($node) {
    if ($node->taxonomy) {
    foreach($node->taxonomy as $term) { $terms[] = $term->tid; }
    return implode('+',$terms);
    }
    else {
    return;
    }
    }
    else {
    return;
    }

    • Check Allow multiple terms per argument
    • Check Reduce duplicates
  5. Now you need to add the second argument in order to exclude the current node from the list. Click [+] button of the arguments section.

  6. Select Node:Nid

  7. Set the "Action to take if argument is not present" to Provide default argument

  8. Set the "Default argument type" to Node ID from URL

  9. Check Exclude the argument

  10. Save your view

You can customize this however you like, such as filtering to a specific content type (ie "News"), can filter by post date, sort by: post date, random, etc.

For a whole discussion on this see http://drupal.org/node/65375

(Sorry for the poor code formatting, not sure how to format code inside a blockquote and list)

2

The context module will help you with that. With it you can show blocks on selected node types, views etc.

0

To create a list of related terms, Laxman's answer is the better way. To show this list only at content type news you can use the Context module as said in googletorp's answer.

  • You can make the block show only on certain content types with the Views approach as well. – Laxman13 Mar 11 '11 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy