I'm trying to display related content on my site. I have two content types, i.e. module and forum. There is also a vocabulary which consists of terms created by NAT using module content types. This vocabulary is used for tagging forum topics. So what i want to do to create a block view to be displayed on module pages listing forum topics tagged with the term corresponding to that module. For example, when you go to Views project page, the forum topics tagged with "Views" term will be listed in a block.
Basically, i'll get the node nid from url and load the related node, get its title and pass it as term name. I thought this would be easy but i couldn't make the view work. I created a block view which lists node titles. I also added a Taxonomy: Term argument with the following php argument code:
if (arg(0)=='node' && is_numeric(arg(1)) { $node = node_load(arg(1));
return $node->title;
}
I selected the basic validation as i don't really know what this is. Now when i enter node/1 as arguments to preview, the resulting query do not get the node nid "1" from the argument code. Instead it gets the "node" part and searches for the term "node". Here is the query:
SELECT node.nid AS nid,
node.title AS node_title
FROM node node
LEFT JOIN term_node term_node ON node.vid = term_node.vid
INNER JOIN term_data term_data ON term_node.tid = term_data.tid
WHERE (node.status <> 0) AND (term_data.name = 'node')
How can i make this work? Any suggestions?
Comments
Comment #1
mooffie commentedThe code you typed kicks in if the argument is missing. That's why it has "Provide default argument" as its title. If an argument is provided, your code won't run at all.
Once you provide arguments there, your code won't get called. That's because the purpose of your code is to provide a default argument, and in this case it's not needed.
You provided two arguments: "node" and "1". The 'Taxonomy: Term' argument is your first (and probably only) argument, so it gets the "node".
(Besides, even if you code did run: You're using the arg() function, and this function always takes its input from what you see in the browser's address bar. Never from what you type in the "arguments to preview".)
I think your code will work as-is if it's in a block. Inside your code you can do
drupal_set_message('blah blah');to help in debugging.Comment #2
drupaloSa commentedYou mean instead of using a view for this, i should create a custom php block with the sql query above?
Comment #3
mooffie commentedNo, no. I meant that your code looked fine to me, and I suggested that you continue with your original plan: to show the *view* in a block (that is, add a 'Block' display and ask Drupal to show it) and everything might possibly be fine.
Comment #4
drupaloSa commentedUnfortunately the view block isn't displayed on the module page (eklenti/16/read-more-tweak.html). Devel shows that the following query is executed:
SELECT node.nid AS nid, node.title AS node_title FROM node node LEFT JOIN term_node term_node ON node.vid = term_node.vid INNER JOIN term_data term_data ON term_node.tid = term_data.tid WHERE (node.status <> 0) AND (term_data.name = '') LIMIT 0, 10As you can see term_data.name check is empty which means there is a problem with the argument. As you've said above, it should be at worst term_data.name = 'eklenti' for this url. Here is my exported view. Perhaps you can find something that i might have done wrong.
Comment #5
drupaloSa commentedI've added a Global: Null (w/ display all values) argument before the Taxonomy: Term in order to get the right argument value for the term name check. Now the preview query makes the
term_data.name = '16'check for node/16. However, php argument code (which should turn 16 to a term name) still doesn't work here.On the live page, the following query is executed which lists all the published nodes as a result in a block:
SELECT node.nid AS nid, node.title AS node_title FROM node node WHERE node.status <> 0 LIMIT 0, 10. Again the term name check (i.e. the 2nd argument) is ignored.According to the views document
I don't know why the second argument and its handling code are ignored completely for the live block view.
Comment #6
drupaloSa commentedNow i tried to create a custom block and embed the view by adding the argument values directly to the view. I used the following code with the view i gave before. The block seems to work! However, i still wonder why the views block did not work in the first place. Could it be a bug?
Btw, is there any difference between these two methods as far as performance is concerned?
Comment #7
mooffie commentedI checked it out. It turns out you have a PHP syntax error. You have:
whereas it sould be:
Except for that, your view works.
So I'm marking this issue 'fixed'.
I don't think there's any difference.
As for performance in general, it's more efficient to work with terms IDs, not term names. Incidentally, there's a module that provides, as a Views argument, the term ID of the "current" node. I can't search for it because Drupal.Org is sluggish right now. Perhaps you'd want to locate it and prod its author to release a D6 version.
Comment #8
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.