Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

gareth connop
gareth connop
14,865 Points

Wordpress forum from scratch

I'm in the process of building a Wordpress theme and so far everything is going well.

I now want to set up a forums section from scratch, so no bbpress etc. Does anyone know how I would begin to do this? Are there any tutorials out there, that anyone knows of?

Thanks

Gareth

12 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

If you just want the experience of building a WordPress plugin, which you would have to do in order to build a forum, then I would suggest first building a simple plugin first that has some of the basic components of a forum. It would almost be easier to build a simple PHP forum from scratch as a beginner than it would be to build it as a WordPress plugin, because not only will you have to think through all the logic, notifications, settings, ability to edit, etc, but you will also have to learn all the WordPress hooks, filters and security best practices for sanitizing data.

I tried searching for tutorials for this, but didn't find any. I'm not surprised. This would be a very very long tutorial and have to cover a lot of different topics. The best I could think of is that you try installing a bunch of different forum plugins, find the simplest one and then begin to study it's source code.

Again, if you're looking for a cool project to learn more about WordPress plugin development, I think you should start with a simpler project. If you actually need a forum on your site, I'd say use bbPress or one of the other one's already built and developed.

Stefan Osorio
Stefan Osorio
16,419 Points

Also worth mentioning: I do understand the wish to understand the code of your site, but are you familiar with the inner workings of Wordpress? I mean, the code of WP Core?

If this is not the case, there would be hardly any difference between using an existing forum plugin (which's internals you aren't familiar with), and building something on WP (which's internals you aren't familiar with).

Stefan Osorio
Stefan Osorio
16,419 Points

I did say that - but personally I try to stay clear of WP in general anyway :)

If you want something "under one roof" and tightly integrated with WP, bbPress would be one of the best solutions I'm aware of. CSS-Tricks recently moved from Vanilla Forums to bbPress, and Chris wrote an article about the experience, you could also check out their forums - seems to be pretty decent :)

gareth connop
gareth connop
14,865 Points

Thanks again. I'll do that

Stefan Osorio
Stefan Osorio
16,419 Points

"I now want to set up a forums section from scratch, so no bbpress etc. Does anyone know how I would begin to do this?"

I'm afraid that this would be well beyond the scope of Wordpress (without plugins). Why exactly do you want to avoid bbPress (or other forum software with tight WP-Integration)?

About six months ago, I attempted to build a WordPress theme with bbPress support baked in.

I love Automattic. I love WordPress. And I love most of Automattic's other products. But do yourself a favor: stay clear of bbPress.

Stefan Osorio
Stefan Osorio
16,419 Points

I'm no fan of bbPress either :) However, i was wondering if Gareth wants to specifically avoid bbPress, or if the focus is on the learning experience / building a forum "from scratch".

gareth connop
gareth connop
14,865 Points

Thanks for your replies.

I'm not specifically trying to avoid bbpress. I just want to build something myself, partly for the learning experience and partly for the fact that I will have an understanding of all of the code in my theme.

Also if I were to use a plugin, which one would you recommend?

To be honest, your best bet really is coding forums from scratch. bbPress provides a lot of functionality right out of the box, but making any attempt to customize that to your site is a nightmare.

gareth connop
gareth connop
14,865 Points

I did think that might be the case. What would be the process in coding forums from scratch? I'm familiar with building a blog from scratch, with custom home.php and single.php files etc, but not sure where to start with forums. Any help would be great.

Thanks

Gareth

I thought I had posted my answer, but I must've closed the page before posting it.

So, the basic anatomy of building the forums from scratch is very similar to your regular blog. You have a bunch of topics (posts) grouped together into individual forums (categories), and there are numerous replies to each topic (comments). If you build out your templates with that in mind, you should be good.

You'll probably want to put a lot of focus on categories and their templates, more so than normal, as these are the highest level in the hierarchy.

gareth connop
gareth connop
14,865 Points

Thanks Ryan, That's good to know. It did seem like it would be a similar process to building a blog, but wasn't completely sure where I would begin, so thanks again for clearing that up.

gareth connop
gareth connop
14,865 Points

Thanks for answering Zac.

I'm not really looking for experience in building a plugin. I just like to know what each piece of code in my site does, so that if there are any issues, I know how it's been built and therefore have a better understanding how to fix it.

I was thinking that it might be possible to create a custom post type for the forums, where you could set the forum titles etc. Each forum would then go to a topics page, which would then go to a topic single page (Like Ryan mentioned above). The topics single page would include comments.

Does this sound feasible? I'm happy for it to only have basic functionality to start with, as I can add improvements as my knowledge around the subject improves.

Zac Gordon
Zac Gordon
Treehouse Guest Teacher

If you want to follow WordPress conventions, you have to build the forum as a plugin. Plugins extend WordPress functionality and themes determine how content is displayed and formatted. Then your theme would have to require the plugin to work properly.

The same goes for custom post types. These should not be part of a theme, but abstracted as a plugin.

The reason is that if someone switches out of your theme they would loose access to edit or display any of their forum data. This breaks WordPress's convention of how themes work.

I hear what you're saying, and it's possible to do the way you want, but from a WordPress Developer's perspective it's not the right way to do it.

Stefan Osorio
Stefan Osorio
16,419 Points

"I was thinking that it might be possible to create a custom post type for the forums[...]"

Yeah... Wordpress as a CMS just isn't really build for that kind of thing. If you want to use core functionality to build out such different parts of your site, you'd probably be better off using a more flexible CMS/CMF (Content Management Framework, a software which is supposed to allow you to build your own stuff), like Drupal or Processwire.

Using Post Types to build a forum in WP would be like using a vertical rotisserie to bake lasagna. Possible: Maybe. But you would not enjoy it ;)

gareth connop
gareth connop
14,865 Points

Thanks Stefan,

Any suggestions on which forum plugin to use in the meantime? Zac mentioned bbpress earlier but both yourself and Ryan have said that you dont really like it.