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->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"'); echo $count . ' comments'; }
Thanks for your help.
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/
Where you want to show this number?
Where you want to show this number?
Just beside the nickname so on the comment page or on hover. 🙂
Thanks
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>'; }
I put the code inside the template function.php but nothing changed.
Is this normal?
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:
It should look like this, we just tested this code:
There is a class="wpdiscuz-comment-count" if you want to style this part:
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:
It should look like this, we just tested this code:
There is a class="wpdiscuz-comment-count" if you want to style this part:
It works, thank you. 🙂
However, how do I change the name of "comments" to another language?
Thanks. 🙂
I have edited this file wpdiscuz-fr_FR.po but everything is already in French but "Comments" and "comment" still in English.
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; }
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
wpDiscuz doesn't have any relation to post titles.
Please leave some URL to allow us understand what do you mean.
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!
Comment count is wrapped in <span> with "wpdiscuz-comment-count" class. You can use that class to style.
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
I'm sorry but I don't have any idea for this website.
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!