How to show nodes of a content type using contextual filters as filters?


Add contextual filter as content type and set value from url path. See screenshots.

enter image description here

enter image description here

After hours of tinkering here is my solution to the above. If anyone has the same requirement this will help:

Drupal 7.16, views-7.x-3.5

The View Setup : enter image description here

The result (sample 1):

enter image description here

Sample 2: enter image description here

No other settings required. Even in the section "WHEN THE FILTER VALUE IS NOT IN THE URL" does not matter, what seems to be important is you set the validation to always return TRUE regardless.

The path of this view is set to /myreports/%

Perhaps, the filter value in the URL that was found will be validated to always true. Then resolves to using this as a normal filter, as is the case with the normal filter setting. Hence, Filter content type = events (or jobs).

The problem with the previous solution is that it will not work for Content Types that have more than one name such as "Press Releases". This worked for me

  1. For Context Filter, select Content Type.
  2. Select "Provide Default Value" and select "PHP Code".
  3. Enter the following snippet of code:

    $node = node_load(arg(1)); echo $node->type;

Tags: Drupal 7 / Views

Similar questions

Is it possible to combine contextual filters with regular filters?
I would like to take my standard taxonomy term view and add a "meta" category that would show up in addition to the term selected. The result should be that items in the meta category show up as well as those in the term being viwewed. I tried adding the meta category as a regular filter or an additional contextual filter, but there's no way to add...
What is the meaning of the field:delta content type offered in contextual filters in views?
When creating a new contextual filter for a view the list of types includes options such as content:spec (field_spec:delta) where spec is the name of a field I have attached to the content type accepted for the view. It appears on some, but not all of the fields offered in the list. I cannot find a reference on this field. What is this (field_name:...
How to display contents which matches the path alias of a content from URL using views contextual filters?
I have a content type "basic" and have contents with different URL alias for ex:;; both are same type. I need to create a view page and the path for that view page is news/newsletter, In this page I want only the content which having the path alias news/newsletter. How can we get t...
Using Contextual Filters to Filter "Content: Published"
Is there any solution to filter "Content: Published" with Contextual Filters?
Show content of type A in content of type B based on shared taxonomy term using views
I want to show content of type A (products) in the middle of contents of type B(Producers), however I do not want to use Node reference since it's an overkill to make it happen with lots of products. So far I have a Vocabulary which both content type share, so I thought if I choose a single taxonomy term when creating the contents of each type, I c...
Displaying a block only for nodes of a specific content type, how do I check the content type using PHP?
I have a block which I would only like displayed on a KYN node. I'm currently using the option to display the block only on pages with "node/*" which worked when I only was using one node type but now that I have two (kYNs and Pages) I need to come up with a solution. I'd like to use some PHP that returns TRUE when the content type of a node KYN. H...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.