简体   繁体   中英

Drupal 7: Combining multiple content type in single view

I have a content type called Author which is referred in another two content types called Novel and Book via Node Reference Module.So we can add author entity to both Book and Novel content types. Both Novel and Book contain another field called Release Date. Now I want to show a block which will display the name of book and name of novel in chronological order based upon the release date when user come to that corresponding Author Page.

Ex. Suppose A is an author who is author of BookA(Release Yr-2006), NovelB(Release Yr-2004),BookC(Release Year-2009). When user come to Author A page then he will be shown a block which will show the Books/Albums in chronological order like this:- NovelB--BookA--BookC

Please suggest as how to achieve in Drupal 7.

You want to display the following field title (I assume the book name is the node title)

For the sorting you can use the sort option in views, it is pretty self-explaining. Choose the name of your release date field.

For the connection between author and books you will have to use a contextual filter (advanced). Add the author-reference-field from your book/novel (the field you use to refer to the author). Then choose to use a default value (2nd option) and choose content id from url . Now your block will find all nodes that refer to the page with the current page-id. Since we chose to display the title fields, you should see a list.

Note that live preview does not work here, so you will have to go to the actual page to see the result.

UPDATE : This works when you have re-used the same field for both content types. If you have uses more then one field you will have to use an OR operator to make the contextual filter work. Thanks to d34dman the following page was given to do just that. Although for new implementations I would recommend using the same field (eg. reference_to_author) for all references from all content types.

Yah..I am able to solve this problem by adding custom code. I have used hook_views_query_alter method and then added join relationship and where clause as per requirement. Please refer to following article for more clarity.. http://www.midwesternmac.com/blogs/jeff-geerling/filtersearch-multiple-fields

Thanks for posting the reply and keeping my hope alive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM