Show Simple Statistics In WordPress Blog

Show Simple Statistics In WordPress Blog

There are many statistics plugins for WordPress, but if you want to show just some basic simple statistics like total posts, comments, categories, users, etc. you might don't want to use these plugins. This article will help you to show this information with some simple codes.

Paste the following code into functions.php file of your theme:

function simple_stats() {
    global $wpdb;

    $stats = array();

    $stats['posts'] = number_format_i18n(wp_count_posts('post')->publish);
    $stats['pages'] = number_format_i18n(wp_count_posts('page')->publish);
    $stats['cats']  = number_format_i18n(wp_count_terms('category'));
    $stats['tags'] = number_format_i18n(wp_count_terms('post_tag'));
    $stats['comments'] = number_format_i18n(wp_count_comments()->approved);

    $stats['users'] = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->prefix}users");

    echo '<div class="simple-stats">',
        '<p>Total posts: <b>', $stats['posts'], '</b></p>',
        '<p>Total pages: <b>', $stats['pages'], '</b></p>',
        '<p>Total categories: <b>', $stats['cats'], '</b></p>',
        '<p>Total tags: <b>', $stats['tags'], '</b></p>',
        '<p>Total comments: <b>', $stats['comments'], '</b></p>',
        '<p>Total users: <b>', $stats['users'], '</b></p>',
        '</div>';
}

Once done, you can use the function in theme files to show statistics:

<?php simple_stats(); ?>

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2024 Deluxe Blog Tips. All rights reserved.

My products: Meta Box | Slim SEO