¿Quieres mostrar el recuento de comentarios de cada usuario junto a su nombre de usuario? Mostrar el recuento de comentarios de cada usuario puede animarles a publicar más comentarios. Veamos cómo mostrar el recuento de comentarios de cada usuario.
Instrucciones:
1. Añade este código al archivo functions.php de tu tema o en un plugin específico del sitio:
<? 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'; } ?>
2. A continuación, añada este fragmento de código al archivo comments.php en el que desea mostrar el recuento de comentarios
<?php commentCount(); ?>
Nota: Si es la primera vez que añade fragmentos de código en WordPress, consulte nuestra guía sobre cómo copiar / pegar correctamente fragmentos de código en WordPress, para no romper accidentalmente su sitio.
Si le gustó este fragmento de código, por favor considere revisar nuestros otros artículos en el sitio como: Los mejores constructores de páginas de WordPress (Comparados).
How do we add this into Users panel? Can we have a new column next to Username, Name, Email, Posts, that would list a comment count, and which you can sort by?
get_comment_author_email() this function not working current user email not find
I allow anonymous posting and end up with user_id = 0 in the comment table, how do I omit the return of this value?
if (user_id > 0) echo commentCount();
I’m guessing something along these lines would work or would it be better to edit the sql queries?
Yes, you may be able to use something like that if it’s consistent. The important thing is to test it out to make sure everything is working.
thanks for this.
Add the first snippet to the functions.php of your wordpress theme, then add the second snippet in the location you want to display the comment count. The place you may want to add it would be beside the users name “comment_author()” you should see that line within your comments.php.
Hi!
I want to display name of the user who is currently logged in and after logs out his name should be with the comment.
i’ve used session but when i logout the session destroys an dthe name and the comment disappears because of unsetting the session.
Thank You!
Hi Kevin, thank you for this tutorial 🙂
I was wondering…do you know how to add the comment for each user as a sortable column in the Admin panel (the user list)?
Thank you in advance for your help,
Roselle
How would you use Transients API with this to cache it? #wordpress
Sent you a link to a great post about this via twitter.
is this only for disqus system?
No this is not just for disqus, should work with any wordpress themes.
I dont see comment author on either comments.php
I am trying to get it in the skeleton theme of wptouch
I have never used that theme but if you add the commentCount() within the comment loop comments should be displayed within a unordered list. It will work, I would have to see the theme file to be sure. Use http://pastebin.com/ to post your code if you wish,
I dont see comment_author
where do we add it?
Add the first snippet to the functions.php of your wordpress theme, then add the second snippet in the location you want to display the comment count. The place you may want to add it would be beside the users name “comment_author()” you should see that line within your comments.php.