{"id":92,"date":"2010-11-13T04:33:36","date_gmt":"2010-11-12T23:33:36","guid":{"rendered":"http:\/\/www.zubair.info\/blog\/?p=92"},"modified":"2019-08-13T19:06:12","modified_gmt":"2019-08-13T14:06:12","slug":"adding-numbers-to-your-wordpress-comments","status":"publish","type":"post","link":"https:\/\/www.zubair.info\/blog\/2010\/11\/13\/adding-numbers-to-your-wordpress-comments.html","title":{"rendered":"Adding Numbers to Your WordPress Comments"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.zubair.info\/blog\/wp-content\/uploads\/2010\/11\/post-add-numbers-to-your-wordpress-comments.gif\" alt=\"Add Numbers to Your WordPress Comments\" title=\"Add Numbers to Your WordPress Comments\" width=\"500\" height=\"200\" class=\"alignnone size-full wp-image-118\" srcset=\"https:\/\/www.zubair.info\/blog\/wp-content\/uploads\/2010\/11\/post-add-numbers-to-your-wordpress-comments.gif 500w, https:\/\/www.zubair.info\/blog\/wp-content\/uploads\/2010\/11\/post-add-numbers-to-your-wordpress-comments-300x120.gif 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/> I was just working on making custom theme, and thought of displaying numbers on version 2.7 &#8211; but since then a lot of things have changed, I noticed the need to change things around a little to achieve the wordpress comment numbering. So this is only for <strong>WordPress version 2.7 and higher<\/strong>. Though, you can achieve the same with older wordpress version by just modifying the position where you place the code. Just to be clear, I have a custom comment callback function like this one: <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">wp_list_comments( array( 'type' =&gt; 'comment', 'callback' =&gt; 'mycustom_comments' ) );<\/pre>\n<p> Do note that I only am using <code>type=comment<\/code> above to show, so this is only numbers the actual comments count and not pingbacks or trackbacks. Before wordpress version 3, i had to fiddle inside the foreach loop like the one below: <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">&lt;?php foreach ($comments as $comment) : ?&gt;<\/pre>\n<p> But not anymore, I just have to go into my custom comment callback function named <code>mycustom_comments<\/code> and do the changes there, I do not have any loops in there. <\/p>\n<p>But i assume wordpress has that function inside the loop so we don&#8217;t really have to worry about anything. Lets start, first go into your comments.php file and find the call to <code>wp_list_comments<\/code> function and add this above it. <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\"> &lt;?php $counter = 0; ?&gt;<\/pre>\n<p> Next, we go into our custom callback function, which should be located somewhere inside the  <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\"> function mycustom_comments( $comment, $args, $depth ) { \/\/this is the function declaration global $counter; \/\/ Make counter variable global so we can use it inside this function. $counter++; <\/pre>\n<p> Finally, add the below code where ever you want the numbers to show. <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\"> &lt;?php echo $counter; ?&gt; <\/pre>\n<p>Sorry, i am writing this post in quite a hurry so if you see something missing, confusing or need to ask something then feel free to comment and let me know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was just working on making custom theme, and thought of displaying numbers on version 2.7 &#8211; but since then a lot of things have changed, I noticed the need to change things around a little to achieve the wordpress comment numbering. So this is only for WordPress version 2.7 and higher. Though, you can [&hellip;]<\/p>\n","protected":false},"author":1001009,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[55,58,54,56,57],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-wordpress-comments","tag-wordpress-functions","tag-wordpress-hacks","tag-wordpress-tricks","tag-wp_list_comments"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/users\/1001009"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":0,"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zubair.info\/blog\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}