1

I am using the Answers module and would like the landing page to display all questions as well as all answers, as they are posted, and each would render different fields e.g. I want the questions and answers to look differently but still show up in the same feed. Currently, it uses a view to list all the questions only. Is this possible?

For an example of what I mean, this is a screenshot Quora.

enter image description here

I read this answer but do not want to use panels, but am also not sure if this solution will render questions and answers differently from each other in the list.

Please notice that the answer shown in this example isn't related to the question; it's just a random answer to a question. That's what I'm looking for.

0

In views, under Advanced, add Relationship Content: Answer to the question

enter image description here

Then in Fields add Content: Answer to the question (Answer to the question)

enter image description here

  • Thank you. I'm not trying to display all the answers to the questions in the view. I'm trying to display answers and questions as they are posted. Basically, I'm trying to render two different content types in two different ways using one view. Is that possible? – Christia Jun 8 '17 at 17:26
  • It is @Christia, add a content type filter and choose "Is one of" - Question , Answer. – dharma Jun 8 '17 at 17:42
  • @Christia yes, your initial view needs to be of Question. (Filter Type = Question). Then the relationship allows you to add answer. – No Sssweat Jun 8 '17 at 17:43
0

You also get a "Answers to a Question" view with this module. Change display format to "Fields" and create a block pulling all the fields you need. You might as well find Relevant Answer (extends Answers) helpful found here.

The module provides two predefined blocks to display questions and their corresponding answers: 'Popular Questions' and 'Recent Questions'.

Edit: Import this view- you should get a "Q & A feed" block which populates questions and its answers, apply a sort criteria to meet your need.

$view = new view();
$view->name = 'q_a_feed';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Q & A Feed';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Q & A Feed';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Answer to the question */
$handler->display->display_options['fields']['field_answer_question']['id'] = 'field_answer_question';
$handler->display->display_options['fields']['field_answer_question']['table'] = 'field_data_field_answer_question';
$handler->display->display_options['fields']['field_answer_question']['field'] = 'field_answer_question';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'answer' => 'answer',
  'question' => 'question',
);

/* Display: Q & A feed */
$handler = $view->new_display('block', 'Q & A feed', 'block');
  • But can I make it so that questions and answers are intermingled as they are posted, or would it be a separate block of answers under a block of questions? – Christia Jun 7 '17 at 22:10
  • Yes the Q & A's are intermingled. Take a look at the "Entity Content" display which is under "Answers to a question" view. It displays answers "bundled" to question and the view is pulling values using a contextual filter (NID from URL). – dharma Jun 8 '17 at 12:25
  • The only display is "master". – Christia Jun 8 '17 at 17:25
  • 1
    Thats weird because I have it. See my edited answer. – dharma Jun 8 '17 at 17:36
  • Thanks for your help. I'm not able to import this view in order to try it due to not having a list of view handlers. But it's good to know it can be done, I'll try to replicate by looking at the code. – Christia Jun 9 '17 at 23:10
0

It's likely not possible to do what I wanted to do, having completely different fields for different content types within one view (as fields, not teasers or entities). I was able to incorporate some of the suggestions by the others who have answered but changed my fields so that they could apply to both content types.

I changed the view to show both questions and answers. I made the number of answers field not show unless there is an answer (so that it doesn't show "Answers:0" in the answers and then I renamed the content types to "Answered" and "Question asked" so that the content shows which one it is. Also, the question title wasn't showing up so I had to read the title field for answers. All is well so far. enter image description here

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.