Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter singsolo

    (@singsolo)

    I think this is a non-issue now. I moved the message to the back end, and just made the plug-in non-functional on the front end.

    singsolo

    (@singsolo)

    I think I may have misread where you want the count. I was, for some reason, thinking you wanted it in the post title, but you want it in the page title.

    Do you want it in all page titles, or just one specific page? If you want it in all page titles, then the function above should work fine, but your filter would be different.

    add_filter('wp_title', 'add_comment_count');

    If you are trying to do it on a specific page, you would need to check for that in your function.

    singsolo

    (@singsolo)

    Well, you can pull the total number of comments from the database. The function would look something like:

    function add_comment_count($content = null) {
         global $wpdb;
    // Run the Query to calculate the total comment count and store the result in the $comment_count variable
         $comment_count = $wpdb->get_row("SELECT count(comment_approved) AS cmmnt_cnt FROM comments WHERE comment_approved = '1' GROUP BY comment_approved", ARRAY_A);
    // Add the count to the end of the content, in this case, the title
         $content .= '('.$comment_count.' Total Comments)';
    //  Finally, return the modified content to be displayed
         return $content;
    }

    Then you would need to add a filter, probably on the “single_post_title” hook.

    add_filter('single_post_title', 'add_comment_count', 5);

    That should get the job done for you.

Viewing 3 replies - 1 through 3 (of 3 total)