Hi,

I'm using Views to create a block that shows news items related to the node the user is currently viewing. This is a little different from the standard method because the news nodes that are related check with a different vocabulary depending on where the user is on the site. If the user is somewhere under primary link A, use vocabulary 5, if the user is somewhere under primary link B, use vocabulary 4.

To simplify this process, I wrote a function in template.php that returns the title of the current page's top-level primary links menu item. My argument handling code looks like this:

$parent = freepress_get_parent2();
if ($parent == 'Free Press Campaigns') {
  $vid = 5; 
} elseif ($parent  == 'Media Issues' ) {
  $vid = 4;
} 

$tids = '';
if($type == 'block' && arg(0) == 'node' && is_numeric(arg(1) ) ){
  $terms = taxonomy_node_get_terms_by_vocabulary(arg(1), $vid);
  foreach($terms as $term){
    $tids[] = $term->tid;
  }
  $tids = implode('+', $tids);
}
return array($tids);

This basically works. freepress_get_parent2(), however, is ugly and I'd like to do it differently. Here's the function:

 function freepress_get_parent2() {
  $current_menu_item = menu_get_item(menu_get_active_item());
  $parent_menu_item = menu_get_item($current_menu_item[pid]);
  $grandparent_menu_item = menu_get_item($parent_menu_item[pid]);
  return $grandparent_menu_item[title];
} 

The code I would like to use is:

 function freepress_get_parent() { 
  $trail = _menu_get_active_trail();
  $root_mid = $trail[1];
	$root_menu_item = menu_get_item($root_mid);
	return $root_menu_item[title];
} 

When I use this preferred function, the View does not display the nodes corresponding to terms from the correct vocabulary, it is as if there is no argument. When I print this function in a block, it prints out the title of the primary link that the current node is underneath in the menu structure, as expected.

My question is: what's wrong with this function? Why doesn't it work correctly with my views argument handling code? Any help would be appreciated.

-Alex

Comments

sun’s picture

Status: Active » Closed (won't fix)

Sorry, unfortunately this support request is way too specific. Please have a look at the issue queue - Views maintainers are buried already. You might want to try to get further support at http://drupal.org/support. Additionally, the answer to your question might be covered in the handbooks at http://drupal.org/handbook/modules/views already.
If you were able to solve this issue on your own in the meantime, you might want to add the involved steps to this closed issue, so other users searching for a similar solution might find it.

akahn’s picture

I ended up using something like the freepress_get_parent2() function above. You're right, this probably should have gone in the forums. Thanks.