When an article is written, various comments from other people may hold great deal of information regarding the topic. That’s why it’s very important to open discussion on web pages. In our company we mainly use WordPress, so I’ll explain how to properly set up comments on WordPress. Our publishing platform Foliopress is based on WordPress version 2.2.3, so screenshots and settings will apply mainly to these versions, but other versions are surely, not so different.
First order of business is allowing discussion in wordpress. Settings for this are in Administration back-end in Options->Discussion. For our company these settings are preferred:
WordPress discussion options
Information on these settings (from WordPress developers) are here.
Some additional information:
- For the first two options( ‘Attempt to notify any Weblogs linked to from the article’, ‘Allow link notifications from other Weblogs’ ), we don’t use pingbacks and trackbacks, but you can read more about it in here and here (broken link – http://www.optiniche.com/blog/117/wordpress-trackback-tutorial/)
- We try to answer comments ASAP, to keep the discussion flourish, so e-mail notification are important for quick response
- We moderate discussion, because we don’t want spam or aggressive and rude statements. This is time consuming but keeps the posts and comments in best quality. And quality is most important.
wordpress discussion settings bottom
It is not that important to blacklist any words, when you setup to moderate discussion, but it is very important if you don’t moderate. Blacklisting will certainly help to separate spam from reasonable comments.
Another setting for comments is in Options->General
wordpress options general
Unchecking ‘Users must be registered and logged in to comment’ will let anybody to post a comment, which we prefer, because it may be annoying for some people to register just for writing a comment, and we may miss a good comment.
That’s for the WordPress setup, but what if some themes doesn’t support comments?
The easiest way is to take the code from default theme. It is located in wp-content/themes/default/comments.php. If this file is not present in theme it doesn’t necessarily means that this theme doesn’t support comments, because the name and path of comments file can be different. Path to the comments file, can be changed inside the theme, or even by plugins. Filter hook, that alters the path to comments file is ‘comments_template’. This is also a name of native WordPress function that includes the comments file, which will be the subject of next chapter of this tutorial.
Next important step is to include comments file in templates for pages and posts. It can be easily done by putting <?php comments_template(); ?>
inside HTML, which will include comments file (or at least try to). So it needs to be inserted inside the post template, usualy ‘wp-content/themes/your-theme/single.php’, and also anywhere else you want comments to appear. Small example of such code can be:
<?php get_header(); ?> <div id="content" class="narrowcolumn"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php the_title(); ?></h2> <div class="entry"> <?php the_content('Read the rest of this page'); ?> <?php wp_link_pages(array('before' => 'Pages: ', 'after' => '', 'next_or_number' => 'number')); ?> </div> </div> <?php endwhile; endif; ?> <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Changed into:
<?php get_header(); ?> <div id="content" class="narrowcolumn"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php the_title(); ?></h2> <div class="entry"> <?php the_content('Read the rest of this page'); ?> <?php wp_link_pages(array('before' => 'Pages: ', 'after' => '', 'next_or_number' => 'number')); ?> </div> </div> <?php endwhile; endif; ?> <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?> <?php comments_template(); ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Comments are always connected with some post or page, so if you don’t load any post or page, function ‘comments_template() will show an error or warning. We allow commenting on both pages and posts, depending on the content of the page.
Of course there’s a way to disable comments for a specific page:
wordpress edit post with allowed comments
By unchecking ‘Allow Comments’ comments will be closed. If there are already some comments on page and we’ll disable commenting, these comments will be displayed on the page (in default template). If there are no comments so far, and commenting is disabled, “Comments are closed” will apear on the page. This actually breaks the integrity of the page, because if commenting is disabled, then it shouldn’t be even mentioned. This text can be removed by editing the comments file. Code structure of displaying comments in default theme (and probably many others) is as follows:
<?php if ($comments) : ?> <!-- Display comments posted so far --> ... <?php else : ?> <?php if ('open' == $post->comment_status) : ?> <!-- If comments are open, but there are no comments. --> <?php else : ?> <!-- If comments are closed. --> <p class="nocomments">Comments are closed.</p> <?php endif; ?> <?php endif; ?> <?php if ('open' == $post->comment_status) : ?> <!-- If comments are opened here is form for posting a comment --> ... <?php endif; ?>
As any, even unexperienced programmer, can see that after the code for displaying already posted comments, there is a part of code that is essentialy unused. So this part can be removed and we’ll end up with this:
<?php if ($comments) : ?> <!-- Display comments posted so far --> ... <?php endif; ?> <?php if ('open' == $post->comment_status) : ?> <!-- If comments are opened here is form for posting a comment --> ... <?php endif; ?>
This way “Comments are closed” sentence is removed, as also some HTML comments which add to network overhead.
Leave a Reply