Posted on March 12th, 2009 in WP Tips-Tricks | 10,982 views

This article will guide you how to display the number of comments on your blog (of course those are approved comments) by a simple php code below.

1
2
3
4
5
6
<?php
global $wpdb;
$num_comments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'");
if ($num_comments > 0) $num_comments = number_format($num_comments);
echo "There are " . $num_comments . " comments on my blog";
?>

Paste the code to places you like in your theme's php files. And this is a live demo :D

There are 1,226 comments on my blog

In the next article, I will guide you how to count the number of posts/pages on your blog. Remember to read! :)

Sign up for News and Updates!
digg delicious stumbleupon technorati Google live facebook Sphinn Mixx newsvine reddit yahoomyweb

11 Responses to “Count the number of comments on your WordPress blog”

  1. Đây là comment thứ 233 trên blog của bạn :D

  2. anh Tom ơi, cho tôi hỏi...
    Làm sao đưa được bộ gõ tiếng việt :o ff,auto,telex...vào comment form được vây?
    thêm vào đó, có nút Preview thật hay. cho tôi học...ké được không?
    xin cảm ơn

  3. Tom ơi cho tớ hỏi làm sao để comment mới nằm trên cùng chứ không gắn vào cuối như hiện tại. Lâu không thấy Tom online chắc bận gái gú a`h

  4. woa, cái này định hỏi mà bác Tom trả lời rùi. Nhanh thiệt! Thx bác 1 cái! \:D/
    Xin hỏi thêm bác 2 đìu nữa.
    - Thứ nhất, làm sao add smiles vào chỗ comments?
    - Thứ hai, hiện bảng bắt buộc nhập mã chống Spam khi comments?

    Hơi quá nhìu, nhưng thx bác trước. Hỏi 1 lần lun để khỏi phiền bác Tom nhìu!

  5. cậu ơi làm sao tính tổng số comment của 1 post hả cậu, có plugin nào ko, skin của mình nó ko có hiện tổng số comment ra, mình muốn chèn vào , giúp mình nha :(

  6. Bác Tom ơi, cho em hỏi: làm sao để việt hóa được cái "viết comment" này ạ.Em thấy "viết comment" của bác hay quá. Em đã việt hóa rùi nhưng chỗ này nó vẫn hiện tiếng anh. (leave a reply , name....). cảm ơn bác nhiều

  7. Chào bạn Hieudt,
    Mình dùng bộ code đếm số lượng phản hồi của bạn,

    Bằng cách:
    Vào giao diện >> widget >> text (văn bản).
    Nhưng không được.
    Có phải Blog của mình dạng: aaa. WordPress.com không hỗ trợ phải không?

    Nhờ giải đáp giúp!

Leave a Reply

Comment moderation is currently enabled so comments with spammy words or a few links might be delayed. Please do not submit your comments twice, they will be approved soon.
Off Auto TELEX VNI VIQR VIQR*