2

Let's say I have two content types: Page and News. Both of them have a field called Tags which is taxonomy term.

Let's say I tag a page and a news item with the term 'celebration'. When a user goes to the page on the front end website, the user should see related news items on the right side bar. A news item is related to a page if they both have at least one tag in common.

I tried to set up a news item block, but i don't know how to tell it to show only news items that share at least 1 tag in common with the page.

1

3 Answers 3

2

I've used the 2.x version of Similar by Terms in the past, and it is very good, with nice views integration. A D7 version of the 2.x branch is in development at http://drupal.org/node/1270244.

The Apache Solr module can also supply a block of nodes that have similar taxonomy terms based on a Solr database: http://drupal.org/project/apachesolr. Very fast, but not trivial to set up.

Finally, here's a comparison of similar/relevant content block modules: http://drupal.org/node/323329.

1

I don't this is good form, but it achieved what I wanted. I created a block then pasted in the php code.

<?php

  if ((arg(0) == 'node') && is_numeric(arg(1))) {

        $sql = "
SELECT node.* FROM node
INNER JOIN field_data_field_tags ON field_data_field_tags.entity_id = node.nid
WHERE node.type = 'document'
AND field_data_field_tags.field_tags_tid IN 

                (SELECT field_tags_tid FROM field_data_field_tags
                INNER JOIN node ON node.nid = field_data_field_tags.entity_id
                WHERE node.nid = ".intval(arg(1)).")
        ";

        $result = db_query($sql);
        while ($row = $result->fetchObject()) {
                echo '<a href="'.url('node/'.$row->nid).'">'.$row->title.'</a>';
        }
?>
2
  • useful, also you can remove current node from result by adding ... AND node.nid != ". arg(1) ." ... Commented Jul 29, 2012 at 19:10
  • Does the trick, but not nearly as cleanly as modules like similarterms. See @jordan's answer below.
    – doub1ejack
    Commented Aug 28, 2013 at 16:23
0

If I understand your question, I think that this module can be useful http://drupal.org/project/similarterms

Similarity is based on the taxonomy terms assigned to content. Blocks are available based on similarity within each of the defined vocabularies for a site as well as a block for similarity within all vocabularies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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