• Skip to content
  • Skip to primary sidebar
  • Skip to footer

Foliovision

Main navigation

  • Weblog
    • FV Player
    • WordPress
    • Video of the Week
    • Case Studies
    • Business
  • About
    • Testimonials
    • Meet the Team
    • We Support
    • Careers
    • Contact
    • Pricing
  • Products
  • Support
    • FV Player Docs
    • Pro Support
  • Login
  • Basket is empty
Affordable VAST/VPAID for Wordpress has arrived. Serve ads with your videos starting today!

The ideal WordPress comment code

30 April 2008 / foliovision / Leave a Comment

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
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
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
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 allow comments
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.

Categories: WordPress Tags: WordPress, wordpress templates

Related Posts

  1. How to Comment Code in WordPress Templates

    How to Comment Code in WordPress Templates

  2. How to Comment Code in WordPress Templates

    How to Comment Code in WordPress Templates

  3. WordPress Comment Ratings Plugins Roundup: Zaki vs Ulike vs Comment Vote vs Voter vs Thumbs Rating vs GD Rating System

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You can click here to Subscribe without commenting

Primary Sidebar

Categories

  • Business
  • Camera Reviews
  • Case Studies
  • Design
  • FV Player
  • Internet Marketing
  • IT
  • Life
  • SEO
  • Slovak
  • Video of the Week
  • WordPress

Footer

Our Plugins

  • FV WordPress Flowplayer
  • FV Thoughtful Comments
  • FV Simpler SEO
  • FV Antispam
  • FV Gravatar Cache
  • FV Testimonials

Free Tools

  • Pandoc Online
  • Article spinner
  • WordPress Password Finder
  • Delete LinkedIn Account
  • Responsive Design Calculator
Foliovision logo
All materials © 2025 Foliovision s.r.o. | Panská 12 - 81101 Bratislava - Slovakia | info@foliovision.com
  • This Site Uses Cookies
  • Privacy Policy
  • Terms of Service
  • Site Map
  • Contact
  • Tel. ‭+421 2/5292 0086‬

We are using cookies to give you the best experience on our website.

You can find out more about which cookies we are using or switch them off in .

Powered by  GDPR Cookie Compliance
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Necessary Cookies

Strictly Necessary Cookie allow you to log in and download your software or post to forums.

We use the WordPress login cookie and the session cookie.

If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

Support Cookies

Foliovision.com uses self-hosted Rocket.chat and self-hosted Freescout support desk to provide support for FV Player users. These cookies allow our visitors to chat with us and/or submit support tickets.

We are delighted to recommend self-hosted Rocket.chat and especially Freescout to other privacy-conscious independent publishers who would prefer to self-host support.

Please enable Strictly Necessary Cookies first so that we can save your preferences!

3rd Party Cookies

This website uses Google Analytics and Statcounter to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.

We reluctantly use Google Analytics as it helps us to test FV Player against popular Google Analytics features. Feel free to turn off these cookies if they make you feel uncomfortable.

Statcounter is an independent Irish stats service which we have been using since the beginning of recorded time, sixteen years ago.

Please enable Strictly Necessary Cookies first so that we can save your preferences!