Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Description
If you want to show a dept counter of all comments you can use this snippet.
The counters work like this:
- 1 comment
- 1 reply
- 2 reply
- 1 reply to reply
- 3 reply
- 2 comment
- 3 comment
Step 1 of 2
Add this to your template.php
/**
* Implementation of hook_preprocess_comment to add the comment_depth_counter to every comment.
*
*/
function YOUR_THEME_NAME_preprocess_comment(&$variables){
static $depths_counter;
$variables['comment_depth_counter'] = ++$depths_counter[$variables['comment']->nid][$variables['comment']->pid];
}
Step 2 of 2
Use the variable $comment_depth_counter in your comment.tpl.php file.
Comments
Should be in core for nodes
I did something similar for numbered node teasers in D7.
Step 2: Use the variable $node_depth_counter in your node.tpl.php file.
For example here:
<div id="node-<?php print $node->nid; ?>" class="<?php print $node_depth_counter; ?> <?php print $classes; ?> clearfix"<?php print $attributes; ?>>
If you ask me, this simple task should be included in core generally. We have sooo many class attributes rendered already, why we don't have a simple counted number ot the node when it gets rendered to the output of more than one node in a page? This would make us possible to define css for every third or 10th node in the list (useful to clearfix in a magazine kind of template for example). I am sure this would be much easier and better performed by getting implementented in core than in prerocessing functions.