Adding a "User Comments" heading before comments list in Drupal 6

Submitted by fabio on Fri, 2010-03-12 15:45.

For a website I'm working on I had the need to display an Heading saying something like "User Comments" just before the user comments list and after the node comments. This can help the website user clearly understand where the node content ends and where the visitors contributions starts.

Something like the following image (In italian):

An example of the final output

How to do it

I though it would have been a complex task: I thought it would have required to override some theming function and hacking deeply into Drupal.

Fortunately it wasn't complex at all. In Drupal 6 there are template files already available to be overriden for a lot of Drupal output.

In this case there is a file called comment-wrapper.tpl.php which we can override in our theme. This file is a wrapper for all the content generated by the comment module (comment lists, comment adding form, etc.).

So we can just place in a file called comment-wrapper.tpl.php within our theme directory the following code:

<?php
// from $Id: comment-wrapper.tpl.php,v 1.2 2007/08/07 08:39:35 goba Exp $
// modified by Fabio Varesano for ermannofalco.com

/**
 * @file comment-wrapper.tpl.php
 * Default theme implementation to wrap comments.
 *
 * Available variables:
 * - $content: All comments for a given page. Also contains sorting controls
 *   and comment forms if the site is configured for it.
 *
 * The following variables are provided for contextual information.
 * - $node: Node object the comments are attached to.
 * The constants below the variables show the possible values and should be
 * used for comparison.
 * - $display_mode
 *   - COMMENT_MODE_FLAT_COLLAPSED
 *   - COMMENT_MODE_FLAT_EXPANDED
 *   - COMMENT_MODE_THREADED_COLLAPSED
 *   - COMMENT_MODE_THREADED_EXPANDED
 * - $display_order
 *   - COMMENT_ORDER_NEWEST_FIRST
 *   - COMMENT_ORDER_OLDEST_FIRST
 * - $comment_controls_state
 *   - COMMENT_CONTROLS_ABOVE
 *   - COMMENT_CONTROLS_BELOW
 *   - COMMENT_CONTROLS_ABOVE_BELOW
 *   - COMMENT_CONTROLS_HIDDEN
 *
 * @see template_preprocess_comment_wrapper()
 * @see theme_comment_wrapper()
 */
?>
<div id="comments">
  <?php if($node->comment_count){ print '<h3 class="comments-intro">' . t("User Comments") . "</h3>"; } ?>
  <?php print $content; ?>
</div>

With the same approach we could add a link to the comment creation form (just adding a link to #comment-form) or adding a disclaimer. Actually with this approach there are lot of possible usage of modifying comment output.

What do you think about my approach? Did you find it useful? Do you have problems implementing it? Feel free to leave me a comment and let me know!

Posted in:

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a personal or company website insert its address in the form http://www.example.com/ .
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <del> <img> <h2> <h3> <h4> <b> <video>
  • Lines and paragraphs break automatically.
  • Images can be added to this post.
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • You may insert videos with [video:URL]

More information about formatting options