0

Say a user has a list of 2 favorite books , one with taxonomy term "adventure" and one with taxonomy term "art". (n favorite books, related with m taxonomy terms)

How to automatically display a list of all books with taxonomy term "adventure" or "art" (or m taxonomy terms)

The steps could be :

  • step 1 : build the list of the user's favorites books (views, flag, filter : this is OK)
  • step 2 : get the list of all taxonomy terms referenced by theses nodes,
  • step 3 : get the list of all books referencing one or several of the taxonomy terms listed at step 2

My question is how to build a view which do these 3 steps.

Thanks

  • It's not very clear what you're asking, what have you tried so far? – Patrick Ryan Jun 18 '15 at 16:40
  • thanks, I added details to my question. It's the first time I put a question on drupal.stackexchange and I am not used to the best pratices : Could you explain why did I get -1 for this question ? – Brigitte Charpent Jun 21 '15 at 14:25
0

You can use views , build a view of content type book , then filter them based on taxonomy term , you even can expose the filter and let it to user to decide which genres want to view .

| improve this answer | |
  • Thank you for helping, but the purpose is not having an exposed filter, the purpose is to automatically display related content (I edited my question). I know how to do it for content related to one single taxonomy term :(contextual filter on the taxonomy term), but I dont' know how to do it with all the taxonomy terms of all the favorites book of the user. – Brigitte Charpent Jun 21 '15 at 14:09
  • How have you stored a user's favorite books? – Alireza Tabatabaeian Jun 21 '15 at 15:18
  • yes, I have stored it. and I have a view for the user's favorites books :list of content type "book" , with relationship "Flags : favorites(by current user, include only flagged content) – Brigitte Charpent Jun 21 '15 at 17:06
0

I found this solution with a chain of relationships :

In Views

Advanced : add a relationship "Flags" : favorites(by current user, include only flagged content) . set identifier to "favorite books" add a relationship "Content: Book_category", relationship : "favorite books", check "Require this relationship). set identifier to "book category" add a relationship : "Taxonomy term: Content using Book_category", relationship : "book category", check "Require this relationship. set identifier to "recommended books"

in Fields :

title, id,book, category etc with relationship : "recommended books"

| improve this answer | |
0

I know your solution is working but I think it might be a time consuming query , too many relationships . I suggest you another solution :

  1. add a new field to users account (type : term reference and link it to your taxonomy vocabulary , I named it Favorite Genre)
  2. Hide it from users using Field Permissions module
  3. Install Rules module
  4. Enable flag actions sub-module
  5. go to Rules and add new rule , event = A node has been flagged, under "your content type"
  6. add an action , add an item to a list (we want to add the books genre to user's favorite)
  7. item to be added is the flaged-node->book_catagory and that must be added to user-flagged-favorite_genre

by now when a user bookmark a book the book genre will be added to his/her favorite genre. the benefit is that there is no need for more querying to find this out.

now go to views add a relation based on user , and you can filter books based on user's favorite genre.

be careful : maybe you do a trick on unbookmark , and remove the book genre from his list , this would be make mistake cause maybe user have other books with this genre . in this case you need to make a loop based on user's bookmarked books and check their genres , if there were no book with that genre then you can remove that genre from user's favorite .

more details about Rules module here.

| improve this answer | |

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.