Greg’s Threaded Comment Numbering: Number Your WordPress 2.7 Comments the Easy Way
New comment handling features in the latest WordPress update broke many of the usual methods that blog administrators use to number comments. But fortunately, you can still take advantage of the new features like threading and paging without giving up comment numbering — all you need is this plugin.
IMPORTANT UPDATE: This plugin now has a newer version! For information on the 1.1 release, please see the update announcement here: “New Version of Comment Numbering Plugin Adds Features and Fixes”. And for the 1.2 release: “WordPress Threaded Comment Numbering Plugin Updated”
Why a WordPress Plugin?
Long time visitors to CounsellingResource.com might know that we run WordPress blog software in several areas of the site — in the Ask the Psychologist section, in our book reviews, and here in our main blog. With the most recent update, WordPress made big changes to its commenting system, and I’ve written a plugin to help blog authors make their comments easier to use for readers.
If you’re not interested in things like running and customising our own blog, you can definitely stop reading now! But if you’re a blogger yourself, using this same platform, feel free to have a gander and see if this WordPress plugin could be something to add to your own box of tools.
Threaded Comment Numbering With a WordPress Plugin
The introduction of WordPress 2.7 brought with it significant new capabilities for threading and paging comments, but these same changes in WordPress mean that well established methods for numbering your comments — like including a basic incrementing counter within your template code — no longer do the trick. But fortunately, taking advantage of modern comment handling features like paging and threading doesn’t have to mean giving up comment numbering altogether.
Coupled with the new template function for displaying comments which debuted in WordPress 2.7, Greg’s Threaded Comment Numbering plugin provides accurate sequential numbering for each comment, including hierarchical numbering for the first level of threaded comments (e.g., comment number 2 and its replies numbered 2.1, 2.2, 2.3, etc.) all 10 levels of threading supported by WordPress.
The plugin numbers comments accurately whether you choose to display them in ascending or descending date order, on multiple pages or on one long page, and with or without threading enabled. It also handles pingback and trackback numbering.
For coders, the plugin provides additional configuration options via direct calls to the function that handles the numbering.
Installing Greg’s Threaded Comment Numbering Plugin
Installation works just like any other WordPress plugin: just unzip the plugin archive and upload it to /wp-content/plugins/ — be sure to upload the entire folder gregs-threaded-comment-numbering. Then you can activate the plugin via the WordPress ‘Plugins’ menu, and configure options via Settings -> Threaded Comment Numbering.
How to Use Greg’s Threaded Comment Numbering Plugin
With a single line of code — either within comments.php or within a callback function defined in functions.php — most WordPress themes which support version 2.7 will also support the comment numbering provided by this plugin.
Basic Usage: The Built-In Comment Callback Function
If you are using the default WordPress theme, or another theme which already supports the new comments features but does not use its own callback function, just replace wp_list_comments() in your theme’s comments.php file with wp_list_comments('callback=gtcn_basic_callback'). (See below for a note on safe wrapping of plugin-dependent function calls.)
The plugin includes some basic styling information suitable for the default theme, but if you’d rather style numbers yourself, you can disable this feature in the plugin’s settings page and provide your own within your template’s CSS file.
Advanced Usage: Calling WordPress Plugin Functions Directly
If your theme already uses a custom callback function, it probably lives in functions.php, and you will see the name of your callback function specified in the call to wp_list_comments() in your comments.php file. You can modify the callback function to incorporate comment numbering wherever you would like it to appear by just adding the following: <?php echo gtcn_comment_numbering($comment->comment_ID, $args); ?>.
(See below for a note on safe wrapping of plugin-dependent function calls.)
If you’re not already using a callback function, but you would like to, creating one is very straightforward. If you’d like, you can use the gtcn_basic_callback() included in the plugin as a starting point for creating your own. Just give your function a new name, drop it into your functions.php file, and specify it as the callback for wp_list_comments() in your comments.php file.
The plugin will automatically detect and respond appropriately if it is asked to provide numbering for a callback function that was itself called to handle pingbacks or trackbacks rather than ordinary comments.
As described above, the plugin provides some basic styling information suitable for the default theme, but you can disable this easily and style comment numbers yourself. In addition to providing your own CSS, you can also specify the class of the <div> wrapper for the comment number by adding an argument to the numbering function call with the name of your preferred class:
<?php echo gtcn_comment_numbering($comment->comment_ID, $args, 'mynumberclass'); ?>.
The default <div> wrapper class is commentnumber.
Safe Wrapping of Plugin-Dependent Function Calls
When updating your theme with any function call that is dependent upon the presence of a plugin, it is good practice to wrap the call within a conditional that checks whether the function is available, as in the following:
<?php if (function_exists('gtcn_basic_callback'))
wp_list_comments('callback=gtcn_basic_callback')
else wp_list_comments(); ?>
Or:
<?php if (function_exists('gtcn_comment_numbering'))
echo gtcn_comment_numbering($comment->comment_ID, $args); ?>
Deactivating and Uninstalling this WordPress Plugin
You can deactivate Greg’s Threaded Comment Numbering plugin via the plugins administration page, and your preferences will be saved for the next time you enable it.
However, if you would like to remove the plugin completely, just disable it via the plugins administration page, then select it from the list of recently deactivated plugins and choose “Delete” from the admin menu. This will not only delete the plugin, but it will also run a special routine included with the plugin which will completely remove its preferences from the database.
Frequently Asked Questions About Greg’s Threaded Comment Numbering Plugin
OK, so these aren’t really ‘frequently asked’ just yet, since I’ve just released the plugin. But I’ll add to this section if other questions really do become frequent.
- Wait! I can’t find
wp_list_comments()in my theme files! How can I use this plugin? - Not all themes have yet been updated to support the new comments function. You can check with the theme’s creator, or there’s an excellent tutorial available if you’d like to tackle the job yourself: Migrating Plugins and Themes to 2.7: Enhanced Comment Display.
- How does Greg’s Threaded Comment Numbering plugin work for pingbacks and trackbacks?
- The plugin will automatically detect and respond appropriately, depending on whether the callback function itself is handling all types of comments, just pingbacks, just trackbacks, etc.
- What if I call the plugin functions from somewhere in my template other than a callback for the
wp_list_comments()function? - The plugin is designed to work in conjunction with a callback function for
wp_list_comments(), and it is only in that context that it will have anything to number. - Does this plugin work with versions of WordPress earlier than 2.7?
- No. The plugin is designed specifically to work with new comment handling features introduced in version 2.7.
- Do you provide support for this plugin?
- No. This plugin is provided in the hopes it might be useful, but without warranty or support of any kind.
Revision History
I’ve moved the revision history to the README file distributed with the plugin.
Fine Print for this WordPress Plugin
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the Plugin!
You can download the plugin right here: Greg’s Threaded Comment Numbering Plugin.
Other articles by Dr Greg Mulhauser, Managing Editor
This article was last reviewed by Dr Greg Mulhauser, Managing Editor on Tuesday, 27th January 2009. You can leave a reply below.
The URL of this page is:
http://counsellingresource.com/features/2009/01/27/threaded-comment-numbering-plugin-for-wordpress/
97 Responses (Including 29 Discussion Threads) to “Greg’s Threaded Comment Numbering Plugin for WordPress”
-
Dardin Kay41
Is there any way that I could change where the number is being displayed? I have looked and found nothing. If it isn’t possible, could you add it in a future release?



« Older Comments