0

I have a content type representing a book. Each book as a genre (SciFi, Fantasy, Thriller ...) and I would like to expose, on the page of a book some books sharing the same genre.

I created a view with a contextual filter on the taxonomy term, but I retrieved the current book so I added a contextual filter on tue current node id to exclude it.

Now I don't retrieve anything from my view.

Each contextual filter on his own his working. If I just use the contextual filter on the content id, I retrieve the list of my books without the current book. If I just use the contextual filter on the taxonomy term, I retrieve the list of my book for that genre (including my current book).

How am I supposed to proceed to have both filter working together ?

3 Answers 3

1

Many of the Drupal features seem magical, but sometimes there are more steps to configure to make them work.

How to use Views Preview with Contextual filters

Contextual filters are strictly linked to individual Fields. It isn't enough to use only the NID Contextual filter (in your Preview) that would then be able to "pull" all the other information, no matter if you have the other Contextual filters set up.

What you enter into the Preview field is what Drupal would take from the URL, or the specified default value as if the URL value is available.

If you have two Contextual filters, you need to enter two filter values into the Preview, one for each filter, in the correct order, separated by /.

To test the complete situation you enter a value for both Contextual filters, for example thriller/35 or 21/35 if Thriller has TID 21 and your first Contextual filter is for term ID and not term name, and 35 is the "current node" NID.

Most Contextual filters have the Exception value set to all. This is a sort of a bypass, the Contextual filter behaves as if it weren't there.

So if you have two Contextual filters and you enter all/all you will see the Views results as if there are no Contextual filters at all.

This is useful when you have to test a Contextual filter while making sure the other one isn't in the way. So you enter all/35 to see all nodes but not the current one (if the current one has NID 35). Or you enter thriller/all so see nodes tagged Thriller but the current one is still on the list.

The Views Preview field (arguments) can test only the part of the Contextual filter that has Provide default value or When the filter value IS available or a default is provided options.

Preview does help to test and configure Contextual filters more quickly, but it doesn't gurantee that you have set them up correctly for cases that don't take values from the URL, so you have to test the Block on the appropriate location anyway.

0

It appears I'm just too stupid to understand Drupal. The view is working when I place a block on the book page. The problem was in the preview with contextual filters. I specified the node id, expecting Drupal to retrieve everything from this id but it appeared it is not enought so it was answering me that No query was run.

0

Use Similar terms module.

Usage:

  1. Create a freetagging vocabulary called "Tags" assigned to the content types on which you'd like to display the "Similar" view block.

    2) Enable the view block called "Similar entries from the Tags vocabulary".

    3) Add keyword tags to the content.

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.