0

I have a node type and two views:

  • One displaying the last 3 elements with a field marked as «important».
  • Another with 3 random elements, marked as important or not.

I don't want the views to repeat nodes.

Since the "lasts" views should always display the last 3 important elements, I thought about filtering the nodes on the random view, but I don't know how.

I managed to do it for a single node in another context. When viewing a node, choosing «Provide default value» with some PHP code combined with the option «Exclude», I can manage to hide that node from the views.

$node = menu_get_object();

if (isset($node->nid)) {
   return $node->nid;
}
else{
  return 0;
}

Suppose I can get the nodes shown on the "lasts" views programatically. Then what? This approach will only work to filter out a single node, not the three I'll get from that view.

Any ideas?

1 Answer 1

0

In the contextual filters, there's an option called «Allow multiple values» just above «Exclude». That option lets you return multiple values separated by commas (and) or mores (or).

So, I just use this code in the «Provide default value» field:

$my_view_name = 'videos';
$my_display_name = 'otros_importantes';

$my_view = views_get_view_result($my_view_name, $my_display_name);
if ( $my_view!=null ) {
  foreach($my_view as $view_row){
    $nodos[]=$view_row->nid;
  }
}

if(isset($nodos)){
  return implode(",",$nodos);
}
else{
  return 0;
}

And that's all, the nodes shown on that display are ignored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.