When I'm on a node that has a taxonomy term associated with it, I want to show a contextual block on the same page using node attach, which shows other items with the same taxonomy term. I keep trying to using arguments but it's not working. Sometimes I get no result and sometimes I just get a repeat of the content already on the page.

I get a repeat of the content if I choose Taxonomy Term ID from URL or if I say Node ID from URL and then try to validate by taxonomy term.

If I say taxonomy Term ID from URL and then validate by taxonomy term or id, I get this error:

Error Description:
Fatal error: Class 'views_plugin_argument_default' not found in /var/www/vhosts/mysite.com/httpdocs/sites/all/modules/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc on line 8

Can you help?

Becky

Comments

beckyjohnson’s picture

I updated to the dev version of this module because I thought my issue was that the token [term] wasn't passing to the nid argument. However, I don't think thats the issue now because I still can't get it to work. I just want to pull in a view of related taxonomy items to the node. How is this so hard to do?

becw’s picture

Status: Active » Needs review

With the "node content" display, views_attach will only supply an NID argument. This means that if you want to find nodes that share a taxonomy term, you have to start from the current node. Your View has to look at the current node --> current node's taxonomy terms --> other nodes with those taxonomy terms.

The "Taxonomy: Node" relationship SHOULD do what you want, except that it is broken--but that's an issue for Views itself...

beckyjohnson’s picture

Thanks for the info. Are all taxonomy term related things broken in views? You know, in terms of relationships and arguments?

I tried out using taxonomy relationships, just to see what would happen, and yeah, it didn't work..

Crell’s picture

Status: Needs review » Closed (works as designed)

Given the way taxonomy works in Drupal 6, yeah, it doesn't play nicely with Views. I honestly gave up on using taxonomy because the integration was so bad. I know merlin was trying to come up with something better but the taxonomy table structure just makes that very difficult.

Since the issue here is with the Views-Taxonomy integration I'm closing this issue. I would refile over to Views but I'm sure there are enough Views-Taxonomy issues there already. :-)

beckyjohnson’s picture

No problem. I understand :)

brycesenz’s picture

I needed to implement this as well, and I think I found a decent workaround that doesn't require TOO much custom coding. You need the PHP View Filter module (http://drupal.org/project/viewsphpfilter), then do the following:

1. Enable the filter "Node: Node ID PHP handler" for the view that you wish to use for Node Content.
2. (Hard-ish part) Write the appropriate PHP code!

For example, if I wanted a my node attachment to be a view of any node which shared at least one taxonomy term, I could write something to this effect:

//get the node's nid
$url_arg = arg(1);
$nid = $url_arg;
$nids = array();
$tids = array();

//get taxonomy terms from argument nid
$my_result = db_query("SELECT tid FROM term_node WHERE nid = '%s'", $nid);
while ($my_row = db_fetch_array($my_result)) {
 $tids[] = $my_row['tid'];
}

//get nids that share the same terms
foreach ($tids as $tid) {
 $my_result2 = db_query("SELECT nid FROM term_node WHERE tid = '%s'", $tid);
 while ($my_row2 = db_fetch_array($my_result2)) {
   $nids[] = $my_row2['nid'];
 }
}

return $nids;

Hope that helps!

beckyjohnson’s picture

Wow! Thanks for posting this. It's really helpful.

ressa’s picture

An alternative way of attaching a contextual block to a node, based on taxonomy term, is to use Similar By Terms module, http://drupal.org/project/similarterms
Remember to filter by content type.

For Views Pages, based on taxonomy term, the Views Attach module works fine!