Building A Stack Overflow Clone With Drupal - Part 3

Stack Overflow brings “group think” to the forefront. Questions and answers are voted on. The more popular a question the better it is. The more popular an answer the more accurate or informative. That’s the impression, anyway. And, if you don’t know what answer is the best others on the site who know better can help you see what the better questions and answers are.

As we explore building a Stack Overflow clone with Drupal we need to explore how to build this form of “group think” into our site.

The Voting Modules

To accomplish the voting we'll need the Voting API and Vote Up/Down modules. Vote Up/Down provides the widget for voting and displaying the results. Voting API provides the back-end magic to make it work. Enable these two modules.

Configuring Vote Up/Down

Head over to Administer > Site configuration > Vote Up/Down configuration to configure the voting. Under Types choose Question and Answer. Then, down under the Vote widget settings for comments settings for Vote widget display set it to Do not display widget and for Link display of vote points set it to Do not display link. Then click, Save configuration.

This will enable voting on the nodes.

The Question View

When the questions are displayed the answers are ordered based on the number of votes. The one with the highest vote is at the top and they go down from there. Head back to the Question view we built in Part 2 of this series and go to the attachment view. The changes we make should only be to this view and should override the default view.

Add a new Relationship of Node: Vote results. For Value type choose Points, for Vote tag choose Normal vote, and for Aggregation function choose Total score.

Add a new Sort criteria of Vote results: Value and set the Sort order to Descending.

Save the view and take the changes for a spin. Next up we look at some of the odds and ends around the site.