Drupal Views, exlude current node or group item from views result list

Views is a powerful module used in Drupal. It enables displaying content in all sorts of ways and flexible manners. Normally, you would fetch a listing or a display of contents with certain requirements, with each listed item clickable and linked to its inner page of that content. Even within the inner pages, you would normally include the same results list somewhere for easy reference, for instance as a sidebar block. The concern now is while on that certain page, the current inner page is still shown in the listing, when it should be already excluded and omitted since the user or visitor is already on that page.

For clarity, an example would be you are already on a news article page, while a Views listing sidebar block of Latest News is still showing and listing the title of this article. You need to exclude that pragmatically - excluding the currently viewed page from the listings block.

Below are the standard steps that are applicable for both Drupal 8 and Drupal 7, and illustrate examples for both excluding a content item and another for excluding a Group item (if using Group module)

How to exclude a current content item from a Views listing or display (Content Item):

  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 dropdown 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"

How to exclude a Group item from a Views listing or results list (Group Module):

  1. Click on the "Advanced" tab.
  2. Click on add under "Contextual Filters".
  3. Choose Group:ID.
  4. Under "When the filter variable is not available, choose "Provide default value".
  5. From the dropdown menu select "Group ID from URL".
  6. Scroll all the way down to the bottom of the window and click on the "More" link.
  7. Click "Exclude"
Leave a Comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
To prevent automated spam submissions leave this field empty.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
10 + 9 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Get reliable web hosting services

Recurring donation

Make Donation

  • Other: $

Donate now

Single donation

Make Donation

  • Other: $

Donate now