On the node page I'd like to add a linked list of other nodes tagged with the same tag/taxonomy term. How can this be achieved? Via Views?
Any help will be highly appreciated
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityThere's a module that does that for you: Similar by Terms. But you can also do this with Views using Contextual Filters & Relationships. This comment on Drupal.org explains it quite well:
Its really easy in D7. Coding is not at all required.
Taxonomy is a field in D7. I will explain how to create a Related Content block using Views.
Create an argument by adding the taxonomy field on which you want to find the related nodes. Select "Provide default argument". Argument type = "Taxonomy Term ID from URL" Remove tick from "Load default argument from term page" Tick the "Load default argument from node page, thats good for related taxonomy blocks." To remove duplicates you have to follow the following points.
Open "Query settings" in the "Advanced Settings". Tick "Distinct". This gives you a perfect "Related Articles" or "Related Nodes" using Views.
Ok, a bit frustrating due to lack of documentation and me being relatively new to Drupal. So here we go:
#Let's find out what term is used
$my_node_tag = $node->field_your_field_used_in_node['und'][0]['tid'];
#Get the array of nodes IDs
$nodeid = taxonomy_select_nodes($my_node_tag, FALSE);
#And here we go
$counter = 0;
foreach($nodeid as $nid) {
$node = node_load($nid);
$alias = drupal_get_path_alias("node/$nid");
print '<div class="title"><a href="' . base_path() . $alias.'">';
print $node->title;
print '</a></div>';
$counter++;
}
Lovely. Not sure how efficient this is, but it works.
Not really needed to install other module when we can achieve this using core ones see this tuto to fond out how.