I want to create a view that dynamically displays all nodes of the child terms of the current node's term. I can create a view that does this for any vocabulary term I select--but I want it the view contents to be generated dynamically for the current page--whatever page that might be.
Does that sound obtuse?
Let me give an example: Let's say I have a hierarchical vocabulary of places; I am currently at the "United States" page, which, not surprisingly, has a taxonomy term of "United States" associated with it.
The "United States" term has child terms which are the states such as "Alabama", "Alaska" .... "Wyoming"
If the page I am on that has the term "United States" as a taxonomy term applied to it, I want to create a list of all nodes that have one of these "child" taxonomy terms applied to it. (Each node would have only one term from this vocabulary applied to it.)
The view that I created that does this statically exports the following:
$view = new stdClass();
$view->name = 'us_child_node_view';
$view->description = 'This Is Test of Chile Node Views';
$view->access = array (
0 => '1',
1 => '2',
);
$view->view_args_php = '';
$view->block = TRUE;
$view->block_title = '';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '999';
$view->block_more = FALSE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
);
$view->argument = array (
array (
'type' => 'taxid',
'argdefault' => '2',
'title' => '',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'defaultsort' => 'ASC',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'story',
),
),
array (
'tablename' => 'term_node',
'field' => 'tid',
'operator' => 'OR',
'options' => '1',
'value' => array (
0 => '11',
),
),
array (
'tablename' => 'term_node_1',
'field' => 'tid',
'operator' => 'NOR',
'options' => '0',
'value' => array (
0 => '11',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node, term_node, term_node_1);
$views[$view->name] = $view;
If you notice, the view filter has two filters that are applied for taxonomy terms: one is to include the children, one is to exclude the present term's node (
array (
'tablename' => 'term_node',
'field' => 'tid',
'operator' => 'OR',
'options' => '1',
'value' => array (
0 => '11',
),
),
array (
'tablename' => 'term_node_1',
'field' => 'tid',
'operator' => 'NOR',
'options' => '0',
'value' => array (
0 => '11',
),
),
Where the '11' is the termID for United States.
SO, how do I create a filter that dynamically inserts the Term ID into the filter?
The post http://drupal.org/node/70145#comment-204051 seems pretty close to doing what I want (filtering dynamically, but with dates instead of Term ID).
I am new to views and I just can't seem to figure out the Argument Handling Code that would create the filter I need.
Or.... am I just barking up the wrong tree altogether? (Pardon the bad hierarchical taxonomy pun!)
Comments
If I wasn't explicit enough...
The nodes I am hoping would be listed are the nodes who are associated with a term that is a state (the nodes child terms of the United States term), such as all nodes accosiated with the terms "Alabama", "Alaska", ... "Wyoming".
I also want the same dynamic view to display the nodes of the provinces of Canada if the current page has a taxonomy term of "Canada" or display the nodes associated with the countries of Europe if the current node is associated with the term Europe.
John Berns
Travel Guide
Travel Photographer
Any ideas?
If somebody could just give me a hint how to get the Term ID, I am sure I could figure out the rest...
John Berns
Travel Guide
Travel Photographer
I am no expert, but I am
I am no expert, but I am trying to do this with departments>courses for school, and I opted to use the directory module and list then it outputs the terms, and I'm trying to alter it to work how I want it. Sorry if I didn't help at all just trying to say what I'm trying to do.
Thanks.
Thanks for the reply, but no, that won't do--this is just one piece of what has to happen on the page. :)
John Berns
Travel Guide
Travel Photographer
Thanks.
Thanks for the reply, but no, that won't do--this is just one piece of what has to happen on the page. :)
John Berns
Travel Guide
Travel Photographer
Dynamic filtering succeeded?
Hi,
Did you succeed in your dynamic filtering?
Please post your solution if you did.
Thanks in advance!
greetings,
Martijn