8

So, I've been trying to get this figured out for most of the day. I had it essentially working in the previewer at one point, but now it doesn't seem to work at all.

Use case: each node published with the content type "Article" comes with a Taxonomy field for included tags. What I'm trying to do is to create a block that appears under the article with a series of thumbnails that link to other articles. These articles in turn are related based on the tags used in each article.

So, the question is:

  1. What would be a good way to set this up using Contextual Filters and Views to have the View itself automatically see the field_tags used as a Taxonomy term reference in an Article, and have it automatically display the output based on the tags of each article?

I've tried setting up the Contextual Filter to be aware that the terms would be in the Content Type: Articles via the Relationships filter, but frankly I'm kind of stumped as to what I need to do to even accomplish this.

1

I have implemented the same in one project in Drupal 7 to display products of same catalog.

You can create a views of article content and can create a contextual filters for tags. It will display all the article of that tags.

You can follow below step:

  • Add a contextual filter of tags. Checked radio button "Provide default value".
  • Select "Taxonomy term Id from url" in the type drop down.
  • Checked "Load default filter from node page" check box.
  • Checked "Limit terms by vocabulary" check box.
  • In the Vocabularies section, checked the check box of Vocabularies (tags) which you want to add filter in the views.
  • Under the more section, checked "Allow multiple values" check box, so multiple tags can use filter the term.

You can find below image for reference.

You also need to add contextual filter of node id and follow below step, so current node page will not display in related views section.

  • Add content: Nid contextual filter in the views.
  • Checked "Provide default value" radio button and select "Content id from url" in the type drop down.
  • Under the more section in contextual filter, checked "Exclude" check box.

display related product in views of same category

0

Have you tried using Similar by Terms?

(edit) The problem with Views taxonomy arguments is that taxonomy is now contained in a field not some voodoo taxonomy module code. Because of this, some of the taxonomy API in Drupal 6 is not available in Drupal 7.

I use the Context module with Views Arguments from Context. I made a patch that ported it Drupal 7. This gives another option under Contexual filter in views to get the arguments based on the context or loaded objects and entities at that time.

This is a particularly uses function:

function taxonomy_node_get_terms($node, $key = 'tid') {
static $terms;
  if (!isset($terms[$node->vid][$key])) {
    $query = db_select('taxonomy_index', 'r');
    $t_alias = $query->join('taxonomy_term_data', 't', 'r.tid = t.tid');
    $v_alias = $query->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
    $query->fields( $t_alias );
    $query->condition("r.nid", $node->nid);
    $result = $query->execute();
    $terms[$node->vid][$key] = array();
    foreach ($result as $term) {
      $terms[$node->vid][$key][$term->$key] = $term;
      }
  }
return $terms[$node->vid][$key];
}

It should not have been removed from Drupal core. It will find the taxonomy terms that you use if you pass it the current node object.

  • No. I'll give it a look, though. My main concern is that I don't want to become overly-dependent on modules, as that can occasionally cause a little instability for a production environment. – John Riley Jun 14 '11 at 20:57
  • similar by terms just creates a view that you can clone. then just disable it when ur done. – user842 Jun 14 '11 at 22:07
  • So, where exactly do I load this function? Do I just modify the taxonomy module somewhere? – John Riley Jun 15 '11 at 15:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.