Divya Manian

RSS Feed Youtube Channel Github

Theme nodes with closed comments in Drupal 6

I use Comment Closer to close comments on old posts to reduce spam on my blog. I wanted visitors to know immediately if a post was no longer accepting comments, and give them alternative means of contacting me about the post. You can see it in action in these two old posts: post with comments, post with no comment. Here is how I did this in Drupal 6:

  • Posts with no comment

    Use the following in node.tpl.php file in your Drupal theme:

    
    <?php if (($page != 0) && isset($node->comment_count) && $node->comment_count < 1) { ?>  
        <?php if($node->comment == 0 || $node->comment == 1) { ?>
        // Enter HTML content you want to render for posts
        // that are closed with no comment.
        <?php else { ?>
        // Enter HTML content you want to render for posts
        // that are open for new comments but have none.
        <?php } 
    } ?> 
  • Posts with comments

    In comment-wrapper.tpl.php, use the following:

    
    <?php if($node->comment == 0 || $node->comment == 1) { ?>
        // Enter HTML content you want to render to inform the visitor
        // that new comments are no longer accepted.
    <?php } ?>  

We need to edit both comment-wrapper.tpl.php and node.tpl.php as comment-wrapper.tpl.php (despite its name) will NOT be rendered if a node has no comments.

Comments