you are here: codestackercodes [RSS] → tag wordpress [RSS]

wordpress functions to count posts

for example: save all functions in 'your_theme/stats.php'

<?php

// comments_count
function comments_count() { 
    global $wpdb; 
    $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"; 
    echo $wpdb->get_var($count); 
} 
// < ?php comments_count() ?> comments

// posts_count
function posts_count() { 
    global $wpdb; 
    $count = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"; 
    echo $wpdb->get_var($count); 
} 
// <?php posts_count() ?></strong> articles

// retro_count
function retro_count() { 
    global $wpdb; 
    $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = 'pingback'"; 
    echo $wpdb->get_var($count); 
} 
// < ?php retro_count() ?> pingbacks

?>
Displaying Code 21 - 21 of 21 in total