Numbering Comments in WordPress
Published: 1 year, 3 months ago (Jun 2, 2009) in How To's/ReviewsTags: wordpress · 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:
- Open
comment-template.php(located directly under/wp-includes) and search for thestart_elfunction. On a vanilla install of 2.7.1, the function begins around line 1200. - Add the following code to the beginning of the function:
- The beginning of your
start_elfunction should now look something like the following: - Next, find the
comments.phpfile for your theme (located in/wp-content/themes/your-theme/) - Add a call to the global
$comment_numvariable by adding the following code to the file: - Finally, select where in the code you would like for your comment number to appear and add this code:
global $comment_num;
if(isset($comment_num)) {
$comment_num++;
} else { $comment_num = 1; }
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;
global $comment_num;
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.
Similar Posts:
Share This Post:

