Building A Stack Overflow Clone With Drupal - Part 4

Posted: November 20, 2009 In

Stack Overflow has dozens of little features that add little magical touches around the site. They help you find things, they help you display things, and they make using the site fairly intuitive. Let's explore how to add a couple of these features to a Drupal site.

Code Highlighting

With Drupal there are a few ways to do code syntax highlighing. The Code filter module lets you highlight PHP. But, who only wants PHP syntax highlighting? There's the Syntax Highlighter module that uses JavaScript. But, that means RSS and browsers with JavaScript turned off can't view the highlighting. And, from a purely performance standpoint, this uses more resources worldwide than the third possible solution.

There is the Geshi Filter Module. This module supports syntax highlight for numerous languages, even some I think of as dead ones. The formatting it produces can be seen in RSS readers and it takes advantage of Drupals filter caching system which is good for performance.

Installing the Geshi Filter module is fairly straight forward. Install the module and follow its instructions on installing the 3rd party Geshi library. Without the library it wont work.

After installing the module go to Administer > Site configuration > GeSHi Filter where you can configure the settings. You can configure the languages to highlight, the HTML tags to enclose the code in, and a bunch of other options.

Then go to Administer > Site configuration > Input formats, select the Input format you want to add it to, and add the Geshi filter.

Tags

Tags provide a simple way to navigate the site. Unlike a forum with a set architecture there isn't a set architecture in a Stack Overflow like setup. This is where tags come it. They provide a way to navigate the site and find what you're looking for.

Tagging in Drupal is there out of the box with the Taxonomy module. Set it up with free tagging on the Question content type. Free tagging is nice but its not always easy to find tags others are using. This is where the Suggested Terms module comes in handy. It suggests popular terms to use.

Both Drupal and Stack Overflow have loads of little niceties. At this point we've built out all the complex parts that aren't intuitive with core or other popular modules.

Reader Comments

Thanks for sharing, I found his very enlightening, Has given me a lot of ideas.

How does one implement the best answer feature?

A best answer feature would be a little bit complicated. You could do a poor mans version of a best answer with the flag module. The problem with this is that you could have multiple answers flagged. To really achieve this functionality you would need some custom code.

Thanks for this tutorial. I must be missing something. When I create the view to show the question and the answers (and comments), the view returns the correct question, but lists ALL answers for all questions, not just the question at the top of the view. Can you offer guidance on what I might be doing wrong in the creation of the view. I have recreated the view several times closely following your instructions, but I must be missing a key step.

Thanks -

Dennis

Do you have the relationship setup as described in http://engineeredweb.com/blog/09/11/building-stack-overflow-clone-drupal...

Thanks for your response Matt. I thought I had followed those instructions precisely. My short term work around for the afternoon was to create to separate views one for questions one for answers and place them in a panel. If you have the time and willingness I could send you a screen shot of the view with attachment that I could not make work. Yours is a far more elegant solution. I assume I have just misunderstood the instructions.

Thanks -

Dennis