Status: Appkillers and memory clearing scripts are useless in Android. Fill-the-memory! (1 hr ago) 


Numbering Comments in WordPress

 Published: 1 year, 3 months ago (Jun 2, 2009) in How To's/Reviews
 Tags: ·  Print This Post ·  Leave a Comment

When modifying a WordPress theme’s comments section, developers may want to include a particular comment’s number in the flow of the other comments of a given post/page. For example, if you look at the meta section of any comment on this site, you’ll see that I’ve incorporated such a feature. Do I have a reason? No. I just had some free time, and wanted to waste a PHP call. ;-)

For those users who do have a reason to implement such a feature, here’s how:

  1. Open comment-template.php (located directly under /wp-includes) and search for the start_el function. On a vanilla install of 2.7.1, the function begins around line 1200.
  2. Add the following code to the beginning of the function:
  3. global $comment_num;
    if(isset($comment_num)) {
    $comment_num++;
    } else { $comment_num = 1; }

  4. The beginning of your start_el function should now look something like the following:
  5. function start_el(&$output, $comment, $depth, $args) {

    global $comment_num;
    if(isset($comment_num)) {
    $comment_num++;
    } else { $comment_num = 1; }
    $depth++;
    $GLOBALS['comment_depth'] = $depth;

  6. Next, find the comments.php file for your theme (located in /wp-content/themes/your-theme/)
  7. Add a call to the global $comment_num variable by adding the following code to the file:
  8. global $comment_num;

  9. Finally, select where in the code you would like for your comment number to appear and add this code:
  10. echo $comment_num;

This method was developed by PannPann and kindly distributed through the WordPress.org support forums. Read through the read to find out how to modify the start_el function to support comment numbering for paged comments.

Share This Post:

Speak Your Mind...

XHTML: You can use these tags: <a href=""> <i> <b> <code>

Gravatar: Want to personalize your comments with a picture? Get a free Gravatar!