How to: Display the total number of trackbacks

December 13, 2008 at 8:59 am

Some time ago, I shown you how to display the total number of comments on your WordPress blog. With a little modification, this recipe can be used to display the total number of trackbacks. This is what I’m going to show you today.

To achieve this recipe, we first have to create a function. paste the following code on the functions.php file from your theme:

function tb_count() {
    global $wpdb;
	$count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = 'pingback' OR comment_type = 'trackback'";
    echo $wpdb->get_var($count);
}

Once the file is saved, you can call the function anywhere you want:

<?php tb_count(); ?>