• Resolved anthony750

    (@anthony750)


    Good morning, sir,

    I would like to put the number of comments next to the nickname of the author of the comment. Before I had the code but after reinstalling the theme I lost the code and it doesn’t work anymore.

    add_filter ('wpdiscuz_comment_author', 'my_commentCount', 10, 2);
    function my_commentCount ($ author_name, $ comment) {
        global $ wpdb;
        $ no_comment = "Aucun commentaire";
        $ one_comment = "Un commentaire";
        $ more_comments = "% commentaires";
         $ count = $ wpdb-> get_var ('SELECT COUNT (comment_ID) FROM'. $ wpdb-> comments. 'WHERE comment_author_email = "'. addlashes ($ comment-> comment_author_email). '"');
        $ comment_text = my_comment_number_text ($ no_comment, $ one_comment, $ more_comments, $ count);
            retourner $ nom_auteur. ' | <span class = "wpdiscuz-comment-count"> '. $ comment_text.' </span> ';
    }
    fonction 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;
    }

    capture

    Awaiting your return,

    Yours sincerely,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support gVectors Support

    (@gvectorssupportmember)

    Hi @anthony750,

    The code works fine, just delete the space after each $ symbol:

    Thread Starter anthony750

    (@anthony750)

    He’s telling me there’s a syntax error, did you find it?

    Capture

    Yours sincerely,

    Plugin Support gVectors Support

    (@gvectorssupportmember)

    Hi @anthony750,

    In the code provided above, there is a wrong part:

    retourner $ nom_auteur. ' | <span class = "wpdiscuz-comment-count"> '. $ comment_text.' </span> ';

    So please replace the code with following one and check again. It should work fine:

    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;
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Comment counter display’ is closed to new replies.