Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In some situations, for example a block listing nodes related to the node being viewed, you might wish to exclude the current node from a list view.
Views 3
- Click on the "advanced" tab.
- Click on add under "contextual filters".
- Choose Content:nid.
- Under "when the filter variable is not available, choose "provide default value".
- From the drop down menu select "content id from url".
- Scroll all the way down to the bottom of the window and click on the "More" link.
- Click "Exclude"
Views 2
Use views arguments, assuming this is a block view
- Add an argument for Node: nid
- Set 'Action to take if argument is not present' to 'Provide default argument'
- Set 'Default argument type' to 'Node ID from URL'
- Check 'Exclude the argument'
If after doing either of the above you are still seeing the current node add another contextual filter for node revisions similar to the Node ID above.
Comments
I need a similar solution for
I need a similar solution for a taxonomy term: show a list of nodes EXCLUDING nodes tagged with the currently viewed taxonomy/term/x tag. Any suggestions?
It is my understanding that
It is my understanding that this is not possible with the Views 2 UI. However, I accomplished something similar by modifying the query via the views_pre_execute hook added to an existing custom module. Not pretty, but not sure there is another way:
function action_user_inquiry_views_pre_execute(&$view) {
if($view->name=="provider_locations_node"
&& $view->current_display=="block_1") {
$view->build_info['query']=preg_replace('/ORDER BY location_node_data_field_primary_address_distance/',
'and users.uid not in(SELECT field_inquired_user_uid FROM content_field_inquired_user WHERE nid = '.arg(1).' ORDER BY location_node_data_field_primary_address_distance',
$view->build_info['query']);
}
}
content_field_inquired_user is a user_reference CCK field, and I want to only show users that are not associated to this field of the current node being displayed (represented by arg(1)). I would love it if there was another way. You could do a similar thing for the term -
where node.nid not in (select nid from term_node where tid='.arg(1).')
instructive
@kmadel: I needed to add a custom sub-query to the Views SQL and your instructive example saved me time--thanks!
John
Were you able to do it? I'm
Were you able to do it? I'm interested doing with Views 3 and Drupal 7.
Thank you
I have realized how to
I have realized how to exclude a node with the same taxonomy.
In Contextual filter, select your field with the taxonomy vocabulary that want to exclude, and in the bottom check the box "exclude".
Thanks!
It can be used for taxonomy terms
Currently the 'exclude' checkbox only shows up for 'numeric' and 'boolean' argument types. Hence it won't show on Taxonomy term name contextual filter, thought it does show on Taxonomy term ID filter (and you can then set the filter value type as 'Term name converted to Term ID' if you need to pass in the term name and not tid).
So yes, you can use the 'exclude' on taxonomy filters!
Thank you. This helped me a
Thank you. This helped me a lot. I spent over two days looking for a solution.
For 6x
To show only nodes from the current node author,
- use uid as argument, then
- select "Provide default argument" then
- select "User ID from URL" and
- check "Also look for a node and use the node author" and save it.
Hope this helps someone
But then how do we not
But then how do we not display the current node in the created list of other nodes by the author? I tried excluding the argument as stated above but then I get nothing at all.
EDIT: Never mind, it just wasn't working in the Views preview is all. Worked fine when I saved the view and actually viewed the node. Thanks for the tip!
views preview (blah)
I was fussing with the Views preview just the other day. It wasn't displaying a block output correctly. I finally wised up and viewed the actual block on a page and it worked as expected.
Exclude current node and viewreference
Hi
this tips works well on preview but not in the node page after...
i include my view in my template via viewreference and this code:
whats wrong ? thanks
Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data
You can also do this like so:
1. Add 'node: nid' argument to the view.
2. Select 'provide default argument'
3. Select 'Node id from url'.
4. Check 'Exclude argument'
I don't remember if you can do this in D5 but in views2 and D6 this works the same.
it works on D6 , thanks
it works on D6 , thanks
Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data
For Drupal 7
The above instructions were a little confusing for me using Drupal 7 + views 3. Here is what I ended up doing that worked:
1. Click on the "advanced" tab.
2. Click on add under "contextual filters".
3. Choose Content:nid.
4. Under "when the filter variable is not available, choose "provide default value".
5. From the drop down menu select "content id from url".
6. Scroll all the way down to the bottom of the window and click on the "More" link.
7. Click "Exclude"
I seem to be having issues
I seem to be having issues doing this in D7 with views 3. I have the exact setup as above and it works on a node page i.e. it excludes the node being viewed. However on say a normal page of another node type or a view, none of the items are displayed. The block is set to be visible using a sitewide context and if I remove the contextual filter altogether the items are displayed correctly on every page, albeit without excluding the node that is being viewed. Any ideas?
Thank you
Just wanted to say THANK YOU!
These steps were so simple. I worked on this for hours before finding your 7 step process.
For Drupal 7 and blocks use...
http://scito.ch/comment/27
Now you need to add the second filter in order to exclude the current node from the list. Click [+] button of the contextual filters section.
Select Content: Nid
Set the ‘when argument is not present’ to ‘Provide default argument’
Set the ‘Default argument type’ to ‘Content ID from URL’
Go to “MORE” , and check the “Exclude” box.
Move the filter “Content: Nid” to the top position.
Add a block to your view and embed the block on your node pages
Save your view
How to add filter if i want to display some node under node/nid
How to add filter if i want to display some node under node/nid from url ?
just for illustration:
node/nid from url is node/9
and i want to display node in views like this
node/8
node/7
node/6
thanks for your help
THIS WORKS
Thanks, using D7, this worked, not problems!
thanks, this is what i needed!
thanks, this is what i needed!
Perfect
Just what I needed!
For those having issues
Block works well in most pages besides the pages created by views were the block seems to disappear altogether.
By doing the following it seems to work as intended
In addition to following the steps for Views 3 do +
When the filter value is available or a default is provided
1. check -> Specify validation criteria
2. Select Basic Validation (or something else that makes sense for the situation)
3. Action to take if filter value does not validate -> Display All Results for the Specified field
It seems that views is passing some kind of argument or invalidates something?
Thanks!
The proposed solution worked fine (the current node was excluded from the list). However, the block containing the view disappeared from every other page, and your suggestion worked like a charm, now the block works as expected in the rest of the site.
This extra step worked for me
This extra step worked for me with pages created by views. Thanks.
Using D7, views 3 and this isn't working for me
Not sure why but I've gone though the steps carefully and whenever I apply the exclusion, it removes all of the content from the view, not just the one with the matching nid.
DetectivePixel's comment brings back the full set of results again, still no exclusion (which I think would make sense).
Suggestions?
This worked for me
Hi,
Not sure if this helps but this is what I did when my whole view went missing.
On the front page the view did not appear, but when going to a content page the view appeared and worked to exclude the node I am on.
I fixed it by adding:
When the filter value IS available or a default is provided
Specify validation criteria
Validator
content
and then the content type(s) the view is filtered to show.
Now the view appears in full form on front page and works on the content pages it is set to exclude current node on.
Thank you very much! Exactly
Thank you very much! Exactly what I needed!
For me, I also needed to uncheck "Specify validation criteria".
I'm using Drupal 7, and Views 3, with a contextual filter on the taxonomy term ID to display related content in a block.
The instructions here didn't work, until I unchecked "Specify validation criteria", which is selected by default. After that, it worked as expected.
And if there is only one node with this taxonomy term ID, it doesn't display the related content block at all; exactly what I wanted.
The more I learn about the finer details of Views, the more I love it.
Worked for Drupal 7.39 like a
Worked for Drupal 7.39 like a charm. Thank you.
Thank You,
Shashwat Purav
Thank you
Thank you so, this solution worked for me. Thanks again.
Re: Exclude the current node from a list view
I think we have pending steps which needs to be implemented:
1. Click on the "advanced" tab.
2. Click on add under "contextual filters".
3. Choose Content:nid.
4. Under "when the filter variable is not available, choose "provide default value".
5. From the drop down menu select "content id from url".
6. Scroll all the way down to the bottom of the window and click on the "More" link.
7. Click "Exclude".
8. In Sort criteria add Global:Random field.
9. Save view & show result on a specific node.
Hope this helps you all!
Many thanks, would have never
Many thanks, would have never looked in the More fieldset. Works like a charm!
How to do this in drupal 8?
How to do this in drupal 8?
It doesn't have the "Exclude" option under "More" :-(
Found it, in portuguese "id"
Found it, in portuguese "id" is translated as "identificador", so I was triyng to use UUID instead, also tried also to use filters, finally the solution was to change to english, and there it was the "id" field and the option to exclude!
Thanks
Thanks a lot for this awesome quick tutorial. You saved my day :)
Thanks this solution worked
Thanks above solution worked for me.
Exclude option is not working
In my case exclude option is not working i have added Relation to my entity reference field as well.
Drupal 9
This is post is very useful. However, I do not see the "More" option in the CONTEXTUAL FILTERS. Is it removed from Drupal 9?
Hi all, I found I cannot see
Hi all, I found I cannot see the "More" potion in the CONTEXTUAL FILTERS because the window is small. You may find it on a bigger monitor or by zooming out the web page. Hope this is helpful for those having the same problem.