how to get the url of a node in a view to pass onto another view.

Events happening in the community are now at Drupal community events on www.drupal.org.
ocamp's picture

Hi, I posted this question on drupal forums but go no response, I then posted in the paid services forum and 3 people couldn't get it to work. So im hoping here will help.

Initially I had a view block that I would display on a node, the view had to arguments :
- Taxonomy Term ID (and children) from URL
- Node ID from URL

But now I'm trying to get the block to display on a view page.

The view page has filters/sort criteria, but only 1 item/node.

So i need to get the TID and NID from the url of the Node displayed in the view.

I was told this would work previously

$view = views_get_page_view();
$nid = $view->handlers['field']['title']->view->result[0]->nid;
$raw = db_query('SELECT tid from {term_node} WHERE nid = %d', $nid);
while ($tid = db_object($raw)) {
  $tids[] = $tid;
}
return implode('+', $tids);

or

if (arg(0) == 'node' && is_int(arg(1)) && !arg(2)) {
  $current_node = node_load(arg(1));
  //you vocabulary ID (vid), CHANGE THIS (HERE)
  $vid = 2;
  $array_tid = array();
  foreach ($node->taxonomy as $taxonomy) {
    if ($taxonomy->vid == $vid) {
      $array_tid[] = $taxonomy->tid;
    }
  }
  if (sizeof($array_tid)) {
    return implode('+', $array_tid);
  }
}

But none worked.

To summarise I have a view page, mysite.com/view1.

View1 only displays 1 node. I have a block created with views which is displayed on mysite.com/view1, so the page displays 2 views.

Im trying to get the TID and NID from the url of the 1 node displayed in view1 to pass into the view block.

In help is greatly appreciated.

Thanks

Comments

Very doable. There are other

scottprive's picture

Very doable. There are other techniques also..

http://drupal.org/node/42599
Also..

Having view1 load view 2 in the view footer would work. You can pass arguments when loading the view.

Or put the args in the URL, and embed PHP code in the view to get it.

Note Panels would be an easier way to process the URL args. Possibly Context module would do it also.

Others will suggest different solutions.. I only use Panels but that has it's own learning curve...

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: