How to Add Another Comment Form when the Comment Count is Large for WordPress Posts?


In wordpress pages/posts, there is a comment form that allows users to post comments. The API for this is comment_form(), which can be found in theme template file comments.php.

By default, the comment form is placed after the list of comments, and therefore, when there are a significant number of comments, the readers won’t find it easy and convenient. The one solution is to place a in-page link that redirects to #respond which jumps directly to the form.

Another solution is place another comment form before the list of comments when there are at least 5 comments for that page. The API required is get_comments_number() which takes an optional parameter $post_id, if omitted, it assumes it is the current page/post.

So, go to comments.php and then add the following code after <?php if ( have_comments() ) : ?>

1
2
3
4
5
<?php // helloacm.com
  if (get_comments_number() >= 5) { // only at least 5 comments
     comment_form(); 
  }
?>
<?php // helloacm.com
  if (get_comments_number() >= 5) { // only at least 5 comments
     comment_form(); 
  }
?>

Each comment_form will be accompanied by a <a name=’respond’> or <div id=’respond’>. So referring to page #respond will jump to the first comment form.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
260 words
Last Post: How to Wrap Selected Text in Edit or TextArea with a Tag in Javascript/HTML?
Next Post: Important Configurations in WordPress Configuration File [wp-config.php]

The Permanent URL is: How to Add Another Comment Form when the Comment Count is Large for WordPress Posts?

Leave a Reply