How to use WordPress to build a website with user-generated content
Written by Verne on January 7th, 2008
User-generated content is not uncommon to websites today and its popularity has grown over the years with the public’s demand to have control and input over what they’re seeing on websites. Sites like Digg, StumbleUpon, and countless others will typically offer a form on the front-end of their website for users to submit content for immediate publishing, enhancing user interactivity and overall experience.
For WordPress users, this is usually a problem because the post and page-writing functionalities are hidden away in the back-end admin panel of WordPress. Not only that, but users are required to have a registered account before being able to access these functions. Add on the fact that logging into the admin panel exposes the user to a different interface and visual environment, and you’ve got yourself a bad user experience and little incentive for the user to want to submit content.
So how do you create a site that offers a usable front-end form that will allow users to publish content immediately onto your site while still taking advantage of the powerful publishing engine of WordPress?
This tutorial will break down one way of overcoming this obstacle using cantwaitforchristmas.com to illustrate examples.
The Case Study
In early December, my agency decided to run a project marathon and pump out a new site from scratch in less than 24 hours. The idea was simple: we wanted to create a single page website that would countdown the days, hours, minutes, and seconds to Christmas, while also letting users submit their Christmas wishes to the site. The structure we had imagined was similar to a Facebook wall in the sense that users would post content (wishes) that would add to a running list of other user-posted content. This was the basis of cantwaitforchristmas.com.
The Concept
Achieving the goal is actually quite simple and just requires looking at WordPress’ basic functions slightly differently. As mentioned, WordPress’ post and page-writing functions are hidden away in the back-end admin panel, but WordPress does offer one other way of publishing content through a front-end form: comments!
The concept then is to isolate the comments functionality and use it to run our wish list form. And because comments always need to be attached to a post or a page, cantwaitforchristmas.com essentially became just one blog post with a lot of comments.
WordPressing
Note: This section assumes that you have general knowledge of how WordPress works and how it is structured.
Once the site design had been designed, chopped up, CSS’d, and WordPressed into its respective sections (i.e. header, body/index, footer), we began modifying the WordPress theme.
Note: The default WordPress theme was used as our base theme, but the idea applies to most, if not all, themes.
There were 4 tasks that needed to be accomplished:
- The main index page must show only a single post.
- The main index page must show the comments for this single post.
- Posting a comment will direct the user back to the main index page (as opposed to the single post page).
- The comments must be listed in descending order (newest at the top).
The following files were used to accomplish these tasks:
- Main index page (index.php)
- Single post page (single.php)
- Comments (comments.php)
Show a single post
To show a single post on the main index page, WordPress’ query_posts() function was used. Learn more about query_posts() here.
To show only the post with ID 1, query_posts('p=1') was inserted before the if / while loops like so:
...
<?php query_posts('p=1'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
...
Alternatively, if we wanted to show just the last post, query_posts('showposts=1') could have been used instead. In our case, it didn’t make a difference since the entire site only needed one post.
Show comments on the main index page
Getting comments to show on the main index page is incredibly easy. Essentially, the main index page (index.php) just needs to be treated as if it were the single post page (single.php).
To do this, <?php comments_template(); ?> was inserted right above <?php endwhile; ?> on index.php, like so:
...
<?php while (have_posts()) : the_post(); ?>
...
<?php comments_template(); ?>
<?php endwhile; ?>
...
Important: In order for this to work, only a single post must be showing on the main index page.
Redirect commenters to the main index page
Another easy task. We simply replaced everything in our single.php file with <?php header('location:/'); ?>. In your case, replace ‘/’ as necessary (i.e. if your site resides in your /blog directory, then replace ‘/’ with ‘/blog’).
When a user posts a comment, the WordPress comment function automatically detects the permalink of the post the user is posting on, and redirects them there, thus calling the single.php file. The <?php header('location:/'); ?> in single.php therefore tells the server to redirect the user back to main index page, rather than display the single post page.
List comments in descending order
When WordPress gets ready to display comments, it compiles all the comments into an array variable named $comments. By default, it orders the comments in ascending chronological order (oldest first, newest last).
Knowing this, a little PHP knowledge was applied to reverse the order of the array. The array_reverse() function was used to make this happen.
We simply inserted <?php $comments = array_reverse($comments, true); ?> right above the comments foreach loop like so:
...
<?php if ($comments) : ?>
<a name="wishes"></a><h3><?php comments_number('nobody has', '1 person has', '% people have' );?> shared their wishes!</h3>
<?php $comments = array_reverse($comments, true); ?>
<?php foreach ($comments as $comment) : ?>
<div id="wish-<?php comment_ID() ?>" class="wishpost">
...
And there you have it, a few tips and tricks that gave cantwaitforchristmas.com its user-generated wishlist!
The Resources
Of course, we came across and used a number of great resources and tools that helped us develop the site that may also be useful for those of you reading this tutorial. Here’s a list of them:
- WordPress Template Tags – a full list of WP tags and how to use them, a great reference guide!
- Comment Relish – a great plugin that helps to extend the user engagement by emailing first-time posters.
- Custom Comment Fields – another useful plugin that helps you build custom forms in AJAX.
- Holiday Social Networking Icons – we used these icons to help our users spread the holiday spirit.
- Snowflakes – the blissful snowflakes that flutter in the background were downloaded from SpoonGraphics.
- Countdown timer – a simple DHTML/JS script that made the countdown to wonderfulness possible.
Final disclaimer: this tutorial represents just one simple way to incorporate a front-end form to help users generate their own content for a website. I’m all about constant-improvement and would love to hear about other methods.
I hope this has been helpful!
If you enjoyed this post, subscribe to the free feed by RSS or Email.
This entry was posted on Monday, January 7th, 2008 at 4:35 pm and is filed under creative briefings, featured, technically speaking. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Marc Ashwell » Blog Archive » links for 2008-01-08
January 8th, 2008 at 5:20 pm[...] How to use WordPress to build a website with user-generated content | creative briefing [...]
Vdot Media - Can't wait for next christmas
January 9th, 2008 at 12:38 amIn early December we built and launched a holiday microsite overnight. Learn about the WordPress magic behind the site and our interview with HatchThat.com.
BlogBuzz January 12, 2007 » Webmaster-Source
January 12th, 2008 at 6:15 am[...] How to use WordPress to build a website with user-generated content [...]
Blogging Insider : How to Use Wordpress for User Generated Content
February 21st, 2008 at 7:25 pm[...] Ho, a creative director based out of Toronto, has a nice case study on how to create user-generated-content using Wordpress. We encourage you to read the full [...]
Dan (future gadgets blog)
February 29th, 2008 at 11:34 amI like your blog theme. I want to use it on my blog.
Can you please tell me from where I can download these theme?
Many thanks
——————————————————————————–
Dan owner of the future gadgets blog future gadgets and inventions
saucybeige blog » Blog Archive » links for 2008-04-22
April 22nd, 2008 at 9:53 am[...] How to use WordPress to build a website with user-generated content | creative briefing So how do you create a site that offers a usable front-end form that will allow users to publish content immediately onto your site while still taking advantage of the powerful publishing engine of WordPress? Achieving the goal is actually quite simple an (tags: wordpress cms) [...]
cilEG
June 22nd, 2008 at 5:32 amAbsolutly AMAZING! Good Job Guys, business download free plan software, business download free plan software, =)),
YPUqx
June 22nd, 2008 at 9:18 amJust Use this site for more informationFind All Youre Looking for here,,
The Best Graphic Design Articles from 34 Top Design Blogs as Chosen By The Authors Themselves | Dalton Trent's Blog
July 1st, 2008 at 10:36 am[...] How to use WordPress to build a website with user-generated content from Creative Briefing [...]
Private Krankenversicherung
September 23rd, 2008 at 3:11 amExcelent blog and comments. Thanks and best regards Private Krankenversicherung
Sophia
November 13th, 2008 at 1:38 amI’m playing around with WordPress. I followed your instructions with using latest query post to get a single post on the index page, then I added the comment code. However, the comment code is not showing up still. Any other suggestions?
usha
February 1st, 2009 at 5:31 ami have just started using wordpress, just going through different articles and making my job easier. This is blog is surely useful. I will come back if i face any problem.
Trovabak
February 2nd, 2009 at 5:27 pm??????? ???: ? ???????? ,? ??????????
affiliate.solutions
February 17th, 2009 at 1:50 amYou have sparked some of my interest and I am going to do some additional research. Feel free to check out some my blog in the near future… as I just posted a great blog about the 36 Best Wordpress plugins for 2009. thanks
HamzaED
March 15th, 2009 at 1:35 am[...] How to use WordPress to build a website with user-generated content | creative briefing – [...]
Cliff Posey
March 18th, 2009 at 12:17 amThanks for the information It is good to read about this kind of innovation, The tools for blogs and websites on the Internet amaze me
Cliff Posey
March 18th, 2009 at 12:41 amThanks for the info. I am always looking to improve with wordpress
Mark
March 26th, 2009 at 2:02 pmI used the following code to make the static front page of my website more dynamic. How would I chage this to show a page instead of a post??
My site is http://www.trueyoumarketing.com
Feature Marketing and Business Article
have_posts()) : $recent->the_post();?>
<a href=”" rel=”bookmark”>
Related Articles
Mark
March 26th, 2009 at 2:03 pmIt chopped off the code??
Feature Marketing and Business Article
have_posts()) : $recent->the_post();?>
<a href=”" rel=”bookmark”>
Related Articles
Mark
March 26th, 2009 at 2:04 pmOh well… Dont know how to past in the code example, just keeps chopping it
Mark
March 26th, 2009 at 2:05 pm‘Feature Marketing and Business Article
have_posts()) : $recent->the_post();?>
<a href=”" rel=”bookmark”>
Related Articles
‘
kartonpiyer
March 27th, 2009 at 9:18 pmi know i am going out of your topic but this is the truth that everyone must know before they order seeing the display…
Thanks for sharing this info anyways
Admiyn
May 7th, 2009 at 11:23 amGreat,
thank you for share
Jye
June 5th, 2009 at 9:42 pmWordpress is easily a great way to build a website with user-generated content.
jsteb
February 12th, 2010 at 11:51 pmNice tutorial… I haven’t had the chance to implement this, but it is just what I need for a pilot site I am working on now. Thanks!
6 Tips for Keeping Your Website (or Blog) Fresh | Blog.TiaWood.com
February 17th, 2010 at 11:01 am[...] might not want to do this with your personal blog but this article is a good read: How to use WordPress to build a website with user-generated content…Furthermore, I believe for niche sites (beside a personal blog) you should give users an [...]
Ora Rubel
March 1st, 2010 at 10:27 amThat’s weird… The page only loads halfways, and I refreshed already :(
Marc Lyman
April 5th, 2010 at 7:20 pmYou might also check out using Gravity Forms. They enable you to have user submitted content that can even create new posts in your site admin. It’s a great tool we’re just starting to play around with on our home improvement site, among others.
shwemyanmar
May 27th, 2010 at 10:29 pmI’m looking for how to allow user to post in my blog. Now, your articles help me alot. thanks
Webwebweb
July 9th, 2010 at 11:13 amUseful tutorial, thanks – just what I was looking for. Any idea if you can make the comments searchable? (For example to search by topic if you want to add other pages on the site?)
Thanks