Notifications
Clear all

Display user comment number / which template for the call?

17 Posts
4 Users
1 Likes
14.4 K Views
(@arena)
Eminent Member
Joined: 8 years ago
Posts: 38
Topic starter  

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.


   
Quote
(@arena)
Eminent Member
Joined: 8 years ago
Posts: 38
Topic starter  

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"... 🙂

http://sgwordpress.com/teaches/how-to-display-user-comment-count-in-wordpress-without-a-plugin/


   
ReplyQuote
 Tom
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4168
 

Where you want to show this number?


   
ReplyQuote
(@arena)
Eminent Member
Joined: 8 years ago
Posts: 38
Topic starter  
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
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4168
 

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)
Eminent Member
Joined: 8 years ago
Posts: 38
Topic starter  

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

Is this normal?


   
ReplyQuote
 Tom
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4168
 

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)
Eminent Member
Joined: 8 years ago
Posts: 38
Topic starter  
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)
Eminent Member
Joined: 8 years ago
Posts: 38
Topic starter  

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

 


   
ReplyQuote
 Tom
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4168
 

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 reacted
ReplyQuote
(@lee_l)
New Member
Joined: 8 years ago
Posts: 1
 

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
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4168
 

wpDiscuz doesn't have any relation to post titles.

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


   
ReplyQuote
(@webminfo)
Eminent Member
Joined: 5 years ago
Posts: 21
 

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
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4168
 

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


   
ReplyQuote
(@webminfo)
Eminent Member
Joined: 5 years ago
Posts: 21
 

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
(@tomson)
Famed Member Admin
Joined: 9 years ago
Posts: 4168
 

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


   
ReplyQuote
(@webminfo)
Eminent Member
Joined: 5 years ago
Posts: 21
 

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:
Scroll to top