wordpress functions to count posts
for example: save all functions in ‘your_theme/stats.php’
1 // comments_count 2 function comments_count() { 3 global $wpdb; 4 $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"; 5 echo $wpdb->get_var($count); 6 } 7 // < ?php comments_count() ?> comments 8 9 // posts_count 10 function posts_count() { 11 global $wpdb; 12 $count = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"; 13 echo $wpdb->get_var($count); 14 } 15 // <?php posts_count() ?></strong> articles 16 17 // retro_count 18 function retro_count() { 19 global $wpdb; 20 $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = 'pingback'"; 21 echo $wpdb->get_var($count); 22 } 23 // < ?php retro_count() ?> pingbacks