0

I am using Drupal 7.

For example, I do not want to show node uid=28 in the list ($page==0). The list page is a "view" without filtering there. So it shows up all the nodes of a specific content type (I only filter with this content type in view setting).

With this function, I can change its title.

function mymodule_node_view($node, $view_mode, $langcode) {
  if ($node->uid == 28) {
    $node->title = "Do not show me!!!";
    $node = NULL;
    unset($node);
  }
}

But I could not work out how to not show up this node at all in the list. I do not want to implement some filtering in view part.

This does not work.

$node = NULL;
unset($node);

I like to use hook_node_view and set more complicated filter logic there.

So basically I like to: implement a view page with only filtering to specific content type that I want; implement a more complicated filtering/selecting method in hook_node_view.

0

1 Answer 1

0

Perhaps I misunderstood the question. You have created a view containing nodes of a special content-type and now you would like to exclude a node with nid equal to 28 from the results? If this is the case then I think you should add a new filter of type Content:nid and set it to not equal 28 in your views configuration page.

Also, I don't think the hook_node_view() can be used to filter the results for a view. You can use the hook to modify or add/remove elements from the node before it's being rendered.

Here is a list of all views hooks.

For example you could use the hook_views_query_alter() to add a new filter to the query.

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.