3

I am trying to create a View that will be a sidebar block on node pages of various content types. The View is pretty basic, just a linked title. I figured I could use Contextual Filters (what used to be Views Arguments in Drupal 6) so I don't have to set up many Views that will all be the same and just use one for all.

My goal is to get only nodes in the sidebar block View of the same type to show up on a node page. So for example on a single Blog node page, the sidebar View will only show other blog stories. However, that same View on a News content type node page will only show other News stories in the View sidebar block and so on...

I have various content types including "News", "Services" and "Blog".

Here is what I have tried so far.

  1. Set up the basic View, showing linked titles.
  2. Added a contextual filter using Content: Type
  3. "When the filter value is NOT available"
    • Provide default value >> Content id from URL
  4. "When the filter value IS available or a default is provided"
    • "Specify validation criteria" >> Validator >> Content >> Checked off the content types I want i.e. Blog, News, Services.

After I save this, no data shows up on any of the node pages. I also tried playing around with other various options in the Contextual settings but to no avail. My google-foo is also failing as everything I found for something like this deals with Taxonomy and that's not what I am after here.

4
  • Maybe duplicate of drupal.stackexchange.com/questions/11979/… Apr 28, 2012 at 3:13
  • If you were using Panels, you could do this by making your view a Content Pane instead of a Block and setting the argument input for the contextual filter to context: content type in the Views UI. Apr 28, 2012 at 7:43
  • @MohammadAliAkbari - yes, I think it is a duplicate. Thanks. Apr 29, 2012 at 14:21
  • @Patrick Kenny I tried that using panels as well and setting my view to Content Pane but from the Panels itself there is no way I could specify a context to be content type. It gives me all sorts of options but no content type. Or should I select Node ID (of the content type)?
    – jan
    Dec 21, 2012 at 7:55

3 Answers 3

1

I don't think you can do it with a contextual filter (without using coding). Just build a view (with block output) for each of the types and then use a filter criteria "content type = news", etc.

It's pretty easy since you can clone the view, then just override the type and change the block name.

1
  • Yes, easy but not necessarily efficient. The whole point was to find something that I would not have to duplicate over and over. Apr 28, 2012 at 17:32
1

Add path aliases by pathauto for each content type. create a view with block and to show contents or fields of contents , then add the Contextual filter : Content: type. From WHEN THE FILTERT VALUE IS NOT AVAILABLE section choose provide default value then select "Raw id from the URL" with depth 1 and check the "use path alias" selected. the view block will work fine. you shoud user views3 to get this worked.

1
  • I did the same thing but for some reason it still doesn't work!
    – SGhosh
    Mar 22, 2013 at 8:59
0

You could provide code like this answer, though PHP is often not available for good security reasons. Ultimately, you'd want to use (or create, if one is not available) a module that provides this functionality to the contextual filters section of the views module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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