Display user comment number / which template for the call?  

  RSS

arena
(@arena)
Eminent Member
Joined: 3 years ago
Posts: 38
27/01/2016 11:48 am  

Hello! I followed the tutorial from this website to make a call to display user total comment number but I don't know where I have to put the php call... Can you please tell me which template I have to put this call? <php commentCount(); ?>   Of course, I already put this content under the template function.php

function commentCount() {
    global $wpdb;
    $count = $wpdb-&gt;get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb-&gt;comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"');
    echo $count . ' comments';
}

Thanks for your help.

This topic was modified 6 months ago by Tom

Quote
arena
(@arena)
Eminent Member
Joined: 3 years ago
Posts: 38
27/01/2016 11:50 am  

I think, it is better for everyone if I put the link to the tutorial because what I wrote above doesn't look good when adding "code"... 🙂

How to Display Every User’s Comment Count in WordPress without a Plugin


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2927
27/01/2016 1:16 pm  

Where you want to show this number?


ReplyQuote
arena
(@arena)
Eminent Member
Joined: 3 years ago
Posts: 38
27/01/2016 8:41 pm  
Posted by: Tom

  Where you want to show this number?

Just beside the nickname so on the comment page or on hover. 🙂

 

Thanks


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2927
28/01/2016 5:27 am  

Ok, instead of your script, you can put this script in theme function.php file:

add_filter('wpdiscuz_comment_author', 'my_commentCount', 10, 2);
function my_commentCount($author_name, $comment) {
    global $wpdb;
    $count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . addslashes($comment->comment_author_email) . '"');
    return $author_name .' | <span class="wpdiscuz-comment-count">'. $count . ' comments</span>';
}

ReplyQuote
arena
(@arena)
Eminent Member
Joined: 3 years ago
Posts: 38
28/01/2016 8:49 am  

I put the code inside the template function.php but nothing changed.

Is this normal?


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2927
29/01/2016 10:10 pm  

I think you've done something incorrect. Maybe you've added this code in other function or class. Or maybe the file you've put it is not the MAIN current active theme functions.php . The functions.php is located on the root of the theme folder.

Make sure you've put it on end of functiosn.php file:

2016 01 29 1805

It should look like this, we just tested this code:

2016 01 29 1804

There is a class="wpdiscuz-comment-count" if you want to style this part:

2016 01 29 1809


ReplyQuote
arena
(@arena)
Eminent Member
Joined: 3 years ago
Posts: 38
30/01/2016 1:29 am  
Posted by: Tom

  I think you've done something incorrect. Maybe you've added this code in other function or class. Or maybe the file you've put it is not the MAIN current active theme functions.php . The functions.php is located on the root of the theme folder. Make sure you've put it on end of functiosn.php file:

2016 01 29 1805

It should look like this, we just tested this code:

2016 01 29 1804

There is a class="wpdiscuz-comment-count" if you want to style this part:

2016 01 29 1809

It works, thank you. 🙂

However, how do I change the name of "comments" to another language?

Thanks. 🙂


ReplyQuote
arena
(@arena)
Eminent Member
Joined: 3 years ago
Posts: 38
30/01/2016 2:32 am  

I have edited this file wpdiscuz-fr_FR.po but everything is already in French but "Comments" and "comment" still in English.

 


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2927
30/01/2016 3:09 am  

Remove the code above, change it to this and change "No comments", "One comment" and "% comments" phrases to your language. Don't remove "%".

add_filter('wpdiscuz_comment_author', 'my_commentCount', 10, 2);
function my_commentCount($author_name, $comment) {
    global $wpdb;
    $no_comment = "No comments";
    $one_comment = "One comment";
    $more_comments = "% comments";
     $count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . addslashes($comment->comment_author_email) . '"');
    $comment_text = my_comment_number_text($no_comment, $one_comment, $more_comments, $count);
        return $author_name .' | <span class="wpdiscuz-comment-count">'.$comment_text.'</span>';
}
function my_comment_number_text( $zero = false, $one = false, $more = false, $number = 0 ) {
    if ( $number > 1 ) { $output = str_replace( '%', number_format_i18n( $number ), $more); } elseif ( $number == 0 ) { $output = $zero; } else { $output = $one; } return $output;
}

	            

arena liked
ReplyQuote
Lee_L
(@lee_l)
New Member
Joined: 3 years ago
Posts: 1
02/03/2016 1:31 pm  

Is it normal to have the number of Comments showing up at the end of Title of each post ???

How do I turn this off ?

I have looked every where.

 

Thanks


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2927
02/03/2016 7:37 pm  

wpDiscuz doesn't have any relation to post titles.

Please leave some URL to allow us understand what do you mean.


ReplyQuote
webminfo.com
(@webminfo)
Active Member
Joined: 7 months ago
Posts: 11
08/01/2019 7:33 pm  

Could you please edit the code a bit? I would like to have own css class for comment count.

Currently, both Name and Comment count using same css class so I can't change style for comment count text.

Thanks for your help!


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2927
08/01/2019 8:16 pm  

Comment count is wrapped in <span> with "wpdiscuz-comment-count" class. You can use that class to style.


ReplyQuote
webminfo.com
(@webminfo)
Active Member
Joined: 7 months ago
Posts: 11
08/01/2019 8:32 pm  

Oh sorry, I saw that class before but I did something wrong. I can add some css change for the comment counter now.

Could you please check this demo page

They're using your plugin and add-ons and they can set different Title for each member

For example: Admin will not display total comment, he has own Title

Comment counter also change the background base total number comments as well. It is very good feature and I really like it

Could you plz tell me how to have feature like that site?

I would like to apply for my sites.

Thanks


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2927
08/01/2019 9:00 pm  

I'm sorry but I don't have any idea for this website.


ReplyQuote
webminfo.com
(@webminfo)
Active Member
Joined: 7 months ago
Posts: 11
14/01/2019 8:45 pm  

Hello TOM,

There is a problem with the code to show Total coments beside username. The Total comments only display for registered user, it does not display total comments guest user.

Could you please modify the code and make it work for everyone including guest author?

Thanks for your help!


ReplyQuote
Share: